package com.mission.schedule.CommonViewController;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.Dialog;
import android.appwidget.AppWidgetManager;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetFileDescriptor;
import android.graphics.Color;
import android.media.MediaPlayer;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.Html;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;

import com.android.volley.AuthFailureError;
import com.android.volley.DefaultRetryPolicy;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.mission.schedule.CommonDialog.CalenderColorDialog;
import com.mission.schedule.CommonDialog.CalenderEditContentDialog;
import com.mission.schedule.CommonDialog.CalenderFlagDialog;
import com.mission.schedule.CommonDialog.CalenderNoteDialog;
import com.mission.schedule.CommonDialog.CalenderRingDialog;
import com.mission.schedule.CommonDialog.SixNewTaskDialog;
import com.mission.schedule.R;
import com.mission.schedule.activity.AddEverydayDetailTaskActivity;
import com.mission.schedule.activity.BaseActivity;
import com.mission.schedule.activity.CalenderNoteEditActivity;
import com.mission.schedule.activity.GuoQiWeiJieShuActivity;
import com.mission.schedule.activity.LingShengActivity;
import com.mission.schedule.activity.MyStateActivity;
import com.mission.schedule.activity.NewResiginActivity;
import com.mission.schedule.activity.NewSixTaskDetailActivity;
import com.mission.schedule.activity.NoteEditActivity;
import com.mission.schedule.activity.NoteListActivity;
import com.mission.schedule.activity.QDFXDetailActivity;
import com.mission.schedule.activity.SchZhuanFaActivity;
import com.mission.schedule.activity.WebViewActivity;
import com.mission.schedule.annotation.ViewResId;
import com.mission.schedule.applcation.App;
import com.mission.schedule.bean.CalenderNoteBean;
import com.mission.schedule.bean.MySchBean;
import com.mission.schedule.bean.RepeatBean;
import com.mission.schedule.bean.WBA_FindFunctionMy;
import com.mission.schedule.bean.qd606.NoteTitleDetailBean;
import com.mission.schedule.clock.QueryAlarmData;
import com.mission.schedule.clock.WriteAlarmClock;
import com.mission.schedule.constants.Const;
import com.mission.schedule.constants.ShareFile;
import com.mission.schedule.entity.CLRepeatTable;
import com.mission.schedule.entity.LocateAllNoticeTable;
import com.mission.schedule.entity.ScheduleTable;
import com.mission.schedule.my160920.FrendLyActivity;
import com.mission.schedule.service.DownRepeatService;
import com.mission.schedule.utils.CalendarChange;
import com.mission.schedule.utils.CharacterUtil;
import com.mission.schedule.utils.DateUtil;
import com.mission.schedule.utils.InWeekUtils;
import com.mission.schedule.utils.MyLinearLayout;
import com.mission.schedule.utils.MyViewPager;
import com.mission.schedule.utils.RepeatDateUtils;
import com.mission.schedule.utils.RepeatSetChildEndUtils;
import com.mission.schedule.utils.SchDateComparator;
import com.mission.schedule.utils.SharedPrefUtil;
import com.mission.schedule.utils.StringUtils;
import com.mission.schedule.utils.UriUtils;
import com.mission.schedule.utils.Utils;
import com.mission.schedule.view.CycleWheelView;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.onekeyshare.OnekeyShare;

public class CommonSearchTagActivity extends BaseActivity implements OnClickListener {

    @ViewResId(id = R.id.top_ll_back)
    private LinearLayout top_ll_back;
    @ViewResId(id = R.id.headtitle_tv)
    private TextView headtitle_tv;
    @ViewResId(id = R.id.all_cb)
    private CheckBox all_cb;
    @ViewResId(id = R.id.noend_cb)
    private CheckBox noend_cb;
    @ViewResId(id = R.id.left_rl)
    private RelativeLayout left_rl;
    @ViewResId(id = R.id.all_tv)
    private TextView all_tv;
    @ViewResId(id = R.id.right_rl)
    private RelativeLayout right_rl;
    @ViewResId(id = R.id.noend_tv)
    private TextView noend_tv;
    @ViewResId(id = R.id.common_listview)
    private ListView common_listview;

    int search_type = 0;
    int search_desc = 0;
    int all_today = 0;
    String time, userid, ringdesc, ringcode, tagId = "", tagname = "";

    SharedPrefUtil sharedPrefUtil = null;
    int width, heigth;
    InWeekUtils inWeekUtils = new InWeekUtils();
    RepeatSetChildEndUtils repeatSetChildEndUtils = new RepeatSetChildEndUtils();
    App app = App.getDBcApplication();

    List<Map<String, String>> mList = new ArrayList<Map<String, String>>();
    List<Map<String, String>> otherlist = new ArrayList<Map<String, String>>();
    List<Map<String, String>> yestodaylist = new ArrayList<Map<String, String>>();
    List<Map<String, String>> todaylist = new ArrayList<Map<String, String>>();
    List<Map<String, String>> tomorrowlist = new ArrayList<Map<String, String>>();
    List<Map<String, String>> inweeklist = new ArrayList<Map<String, String>>();
    List<Map<String, String>> outweeklist = new ArrayList<Map<String, String>>();
    List<Map<String, String>> allList = new ArrayList<Map<String, String>>();

    CommonSearchTagAdapter commonSearchTagAdapter;
    View headView;
    TextView all_t, outtwoday_t;

    @Override
    protected void setListener() {
        top_ll_back.setOnClickListener(this);
        all_cb.setOnClickListener(this);
        noend_cb.setOnClickListener(this);
    }

    @Override
    protected void setContentView() {
        setContentView(R.layout.common_search_tag_activity);
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        String title = getIntent().getStringExtra("search_title");
        search_type = getIntent().getIntExtra("search_type", 0);
        search_desc = getIntent().getIntExtra("search_desc", 0);
        headtitle_tv.setText(title);

        sharedPrefUtil = new SharedPrefUtil(this, ShareFile.USERFILE);
        userid = sharedPrefUtil.getString(this, ShareFile.USERFILE,
                ShareFile.USERID, "");
        time = sharedPrefUtil.getString(this, ShareFile.USERFILE,
                ShareFile.ALLTIME, "08:58");
        ringdesc = sharedPrefUtil.getString(this, ShareFile.USERFILE,
                ShareFile.MUSICDESC, "完成任务");
        ringcode = sharedPrefUtil.getString(this, ShareFile.USERFILE,
                ShareFile.MUSICCODE, "g_88");

        /**
         * 获取屏幕的高度和宽度
         */
        DisplayMetrics metric = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metric);
        width = metric.widthPixels;
        heigth = metric.heightPixels;

        headView = LayoutInflater.from(this).inflate(R.layout.fragment_allday_head, null);
        all_t = (TextView) headView.findViewById(R.id.all_tv);
        outtwoday_t = (TextView) headView.findViewById(R.id.outtwoday_tv);

        common_listview.addHeaderView(headView);

        all_t.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                outtwoday_t.setVisibility(View.VISIBLE);
                all_t.setVisibility(View.GONE);
                loaddata(search_type);
            }
        });
        outtwoday_t.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                outtwoday_t.setVisibility(View.GONE);
                all_t.setVisibility(View.VISIBLE);
                loaddata(search_type);
            }
        });

        loaddata(search_type);


        if (allList != null && allList.size() > 0) {
            headView.setPadding(0, Utils.dipTopx(this, 20), 0, 0);
            headView.setVisibility(View.VISIBLE);
        } else {
            headView.setPadding(0, Utils.dipTopx(this, -10), 0, 0);
            headView.setVisibility(View.GONE);
        }

    }

    boolean headflag;

    private void loaddata(final int search_type) {
        otherlist.clear();
        yestodaylist.clear();
        todaylist.clear();
        tomorrowlist.clear();
        inweeklist.clear();
        outweeklist.clear();
        allList.clear();
        mList.clear();

        all_tv.setTextColor((all_today == 0) ? getResources().getColor(R.color.endbackground) : getResources().getColor(R.color.important_text_color));
        noend_tv.setTextColor((all_today == 0) ? getResources().getColor(R.color.important_text_color) : getResources().getColor(R.color.endbackground));


        if (search_type == SearchType.RENWU.ordinal()) {
            headflag = true;
            loadDataComeFriend(all_today);
        } else if (search_type == SearchType.IMPORT.ordinal()) {
            headflag = true;
            loadDataImpront();
        } else if (search_type == SearchType.DAIBAN.ordinal()) {
            headflag = false;
            loadDataDaiban();
        } else if (search_type == SearchType.DAOQIRI.ordinal()) {
            headflag = false;
            loadDataDaoqiri();
        } else {
            headflag = false;
            loadDataTag();
        }
        setAdapter();
    }

    //以前数据
    private void loadDataComeFriend(int all_today) {
        try {
            if (all_today == 0) {
                if (all_t.getVisibility() == View.VISIBLE) {
                    allList = app.queryAllSchData(37, 0, 0);
                } else {
                    otherlist = app.queryAllSchData(38, 0, 0);
                }
                yestodaylist = app.queryAllSchData(39, 0, 0);
                todaylist = app.queryAllSchData(40, 0, 0);
                tomorrowlist = app.queryAllSchData(41, 0, 0);
                inweeklist = app.queryAllSchData(42, 0, 0);
                outweeklist = app.queryAllSchData(43, 0, 0);
            } else {
                otherlist = app.queryAllSchData(44, 0, 0);
                yestodaylist = app.queryAllSchData(45, 0, 0);
                todaylist = app.queryAllSchData(46, 0, 0);
                tomorrowlist = app.queryAllSchData(47, 0, 0);
                inweeklist = app.queryAllSchData(48, 0, 0);
                outweeklist = app.queryAllSchData(49, 0, 0);
            }

            Collections.sort(otherlist, new SchDateComparator());

            mList.addAll(otherlist);
            mList.addAll(yestodaylist);
            mList.addAll(todaylist);
            mList.addAll(tomorrowlist);
            mList.addAll(inweeklist);
            mList.addAll(outweeklist);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    private void loadDataImpront() {
        // 1 两天以前 2 昨天 3今天 4明天 5一周以内 6一周以后
        try {

            if (all_today == 0) {
                if (all_t.getVisibility() == View.VISIBLE) {
                    allList = app.queryAllSchData(24, 0, 0);
                } else {
                    otherlist = app.queryAllSchData(25, 0, 0);
                }
                yestodaylist = app.queryAllSchData(26, 0, 0);
                todaylist = app.queryAllSchData(27, 0, 0);
                tomorrowlist = app.queryAllSchData(28, 0, 0);
                inweeklist = app.queryAllSchData(29, 0, 0);
                outweeklist = app.queryAllSchData(30, 0, 0);
            } else {
                otherlist = app.queryAllSchData(31, 0, 0);
                yestodaylist = app.queryAllSchData(32, 0, 0);
                todaylist = app.queryAllSchData(33, 0, 0);
                tomorrowlist = app.queryAllSchData(34, 0, 0);
                inweeklist = app.queryAllSchData(35, 0, 0);
                outweeklist = app.queryAllSchData(36, 0, 0);
            }

            Collections.sort(otherlist, new SchDateComparator());

            mList.addAll(otherlist);
            mList.addAll(yestodaylist);
            mList.addAll(todaylist);
            mList.addAll(tomorrowlist);
            mList.addAll(inweeklist);
            mList.addAll(outweeklist);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private void loadDataDaiban() {
        try {
            if (all_today == 0) {
                mList.clear();
                if (all_t.getVisibility() == View.VISIBLE) {
                    mList.addAll(app.queryAllSchData(-6, 0, 0));
                } else {
                    mList.addAll(app.queryAllSchData(-0, 0, 0));
                }
            } else {
                mList.addAll(app.queryAllSchData(0, 0, 0));
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void loadDataDaoqiri() {
        // 1 两天以前 2 昨天 3今天 4明天 5一周以内 6一周以后
        try {

            if (all_today == 0) {
                if (all_t.getVisibility() == View.VISIBLE) {
                    allList = app.queryAllSchData(65, 0, 0);
                } else {
                    otherlist = app.queryAllSchData(66, 0, 0);
                }
                yestodaylist = app.queryAllSchData(67, 0, 0);
                todaylist = app.queryAllSchData(68, 0, 0);
                tomorrowlist = app.queryAllSchData(69, 0, 0);
                inweeklist = app.queryAllSchData(70, 0, 0);
                outweeklist = app.queryAllSchData(71, 0, 0);
            } else {
                otherlist = app.queryAllSchData(72, 0, 0);
                yestodaylist = app.queryAllSchData(73, 0, 0);
                todaylist = app.queryAllSchData(74, 0, 0);
                tomorrowlist = app.queryAllSchData(75, 0, 0);
                inweeklist = app.queryAllSchData(76, 0, 0);
                outweeklist = app.queryAllSchData(77, 0, 0);
            }

            Collections.sort(otherlist, new SchDateComparator());

            mList.addAll(otherlist);
            mList.addAll(yestodaylist);
            mList.addAll(todaylist);
            mList.addAll(tomorrowlist);
            mList.addAll(inweeklist);
            mList.addAll(outweeklist);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    private void loadDataTag() {
        // 1 两天以前 2 昨天 3今天 4明天 5一周以内 6一周以后
        try {

            if (all_today == 0) {
                otherlist = app.queryAllSchData(50, 0, search_desc);
                yestodaylist = app.queryAllSchData(51, 0, search_desc);
                todaylist = app.queryAllSchData(52, 0, search_desc);
                tomorrowlist = app.queryAllSchData(53, 0, search_desc);
                inweeklist = app.queryAllSchData(54, 0, search_desc);
                outweeklist = app.queryAllSchData(55, 0, search_desc);
            } else {
                otherlist = app.queryAllSchData(56, 0, search_desc);
                yestodaylist = app.queryAllSchData(57, 0, search_desc);
                todaylist = app.queryAllSchData(58, 0, search_desc);
                tomorrowlist = app.queryAllSchData(59, 0, search_desc);
                inweeklist = app.queryAllSchData(60, 0, search_desc);
                outweeklist = app.queryAllSchData(61, 0, search_desc);
            }

            Collections.sort(otherlist, new SchDateComparator());

            mList.addAll(otherlist);
            mList.addAll(yestodaylist);
            mList.addAll(todaylist);
            mList.addAll(tomorrowlist);
            mList.addAll(inweeklist);
            mList.addAll(outweeklist);

            if (mList.size() == 0) {

                if (all_today == 0) {
                    otherlist = app.queryAllSchData(50, 0, search_type);
                    yestodaylist = app.queryAllSchData(51, 0, search_type);
                    todaylist = app.queryAllSchData(52, 0, search_type);
                    tomorrowlist = app.queryAllSchData(53, 0, search_type);
                    inweeklist = app.queryAllSchData(54, 0, search_type);
                    outweeklist = app.queryAllSchData(55, 0, search_type);
                } else {
                    otherlist = app.queryAllSchData(56, 0, search_type);
                    yestodaylist = app.queryAllSchData(57, 0, search_type);
                    todaylist = app.queryAllSchData(58, 0, search_type);
                    tomorrowlist = app.queryAllSchData(59, 0, search_type);
                    inweeklist = app.queryAllSchData(60, 0, search_type);
                    outweeklist = app.queryAllSchData(61, 0, search_type);
                }

                Collections.sort(otherlist, new SchDateComparator());

                mList.addAll(otherlist);
                mList.addAll(yestodaylist);
                mList.addAll(todaylist);
                mList.addAll(tomorrowlist);
                mList.addAll(inweeklist);
                mList.addAll(outweeklist);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void setAdapter() {
        commonSearchTagAdapter = new CommonSearchTagAdapter(this, mList, R.layout.adapter_timeall_item_new, handler, width);
        common_listview.setAdapter(commonSearchTagAdapter);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.top_ll_back:
                this.finish();
                break;

            case R.id.all_cb://全部
                all_cb.setChecked(true);
                noend_cb.setChecked(false);
                all_today = 0;
                if (headflag) {
                    headView.setPadding(0, Utils.dipTopx(this, 20), 0, 0);
                    headView.setVisibility(View.VISIBLE);
                }
                loaddata(search_type);
                break;

            case R.id.noend_cb://今天+未结束
                all_cb.setChecked(false);
                noend_cb.setChecked(true);
                all_today = 1;
                if (headflag) {
                    headView.setPadding(0, Utils.dipTopx(this, -20), 0, 0);
                    headView.setVisibility(View.GONE);
                }
                loaddata(search_type);
                break;
        }
    }

    /**
     * 删除日程
     */
    private void deleteItem(final Map<String, String> mMap) {
        final AlertDialog builder = new AlertDialog.Builder(CommonSearchTagActivity.this)
                .create();

        builder.show();
        Window window = builder.getWindow();
        android.view.WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
        params.alpha = 0.92f;
        window.setAttributes(params);// 设置生效
        window.setContentView(R.layout.dialog_alterdelete);
        TextView delete_ok = (TextView) window.findViewById(R.id.delete_ok);
        TextView delete_canel = (TextView) window
                .findViewById(R.id.delete_canel);
        delete_canel.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                commonSearchTagAdapter.notifyDataSetChanged();
                builder.dismiss();
            }
        });
        TextView delete_tv = (TextView) window.findViewById(R.id.delete_tv);

        delete_tv.setText("确定要结束此日程吗?");

        delete_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                endCalender(mMap);
                builder.dismiss();
            }
        });
    }


    private Handler handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            Intent intent = null;
            final Map<String, String> mMap = (Map<String, String>) msg.obj;
            Map upMap = null;
            String value = "0";
            final int position = msg.arg1;

            switch (msg.what) {
                case 0:// 点击菜单(详情菜单)
                    if (mList.size() > 0) {
                        Map<String, String> map = App.getDBcApplication().QueryhongFuData(mList.get(position).get(ScheduleTable.schRepeatID));
                        if (map != null) {
                            if (!map.get(CLRepeatTable.remark2).isEmpty()) {
                                WBA_FindFunctionMy.ListBean bean = App.getDBcApplication().get_tb_function_my(map.get(CLRepeatTable.remark2));
                                if (bean != null && !bean.url.isEmpty()) {Intent x = new Intent(CommonSearchTagActivity.this, WebViewActivity.class);
                                    x.putExtra("url", bean.url);
                                    x.putExtra("remark2", bean.id + "");
                                    x.putExtra("fun_id", bean.id + "");
                                    x.putExtra("schID", mMap.get(ScheduleTable.schID));
                                    startActivityForResult(x, 100);
                                } else {
                                    detail(mMap, intent, position);
                                }
                            } else if (map.get(CLRepeatTable.repContent).length() > 2 && map.get(CLRepeatTable.repContent).substring(0,2).equals("#%")) {
                                List<CalenderNoteBean.PageBean.ItemsBean> list =
                                        App.getDBcApplication().getCalenderNoteDetailData(userid, map.get(CLRepeatTable.repSourceDesc), false);
                                if (list.size() >= 1 && UriUtils.isUrl(list.get(0).contents)) {
                                    Intent x = new Intent(CommonSearchTagActivity.this, WebViewActivity.class);
                                    x.putExtra("url", list.get(0).contents);
                                    x.putExtra("remark2", map.get(CLRepeatTable.repContent));
                                    x.putExtra("fun_id", "");
                                    x.putExtra("schID", mMap.get(ScheduleTable.schID));
                                    startActivityForResult(x, 100);
                                } else {
                                    detail(mMap, intent, position);
                                }
                            } else {
                                detail(mMap, intent, position);
                            }
                        } else if(mMap.get(ScheduleTable.schRemark6) != null) {
                            WBA_FindFunctionMy.ListBean bean = App.getDBcApplication().get_tb_function_my(mMap.get(ScheduleTable.schRemark6));
                            if (bean != null && !bean.url.isEmpty()) {
                                Intent x = new Intent(CommonSearchTagActivity.this, WebViewActivity.class);
                                x.putExtra("url", bean.url);
                                x.putExtra("remark2", bean.id + "");
                                x.putExtra("fun_id", bean.id + "");
                                x.putExtra("schID", mMap.get(ScheduleTable.schID));
                                startActivityForResult(x, 100);
                            } else if (mMap.get(ScheduleTable.schContent).length() > 2 && mMap.get(ScheduleTable.schContent).substring(0,2).equals("#%")) {
                                List<CalenderNoteBean.PageBean.ItemsBean> list =
                                        App.getDBcApplication().getCalenderNoteDetailData(userid, mMap.get(ScheduleTable.schSourceDesc), false);
                                if (list.size() >= 1 && UriUtils.isUrl(list.get(0).contents)) {
                                    Intent x = new Intent(CommonSearchTagActivity.this, WebViewActivity.class);
                                    x.putExtra("url", list.get(0).contents);
                                    x.putExtra("remark2", mMap.get(ScheduleTable.schContent));
                                    x.putExtra("schID", mMap.get(ScheduleTable.schID));
                                    x.putExtra("fun_id", "");
                                    startActivityForResult(x, 100);
                                } else {
                                    detail(mMap, intent, position);
                                }
                            } else {
                                detail(mMap, intent, position);
                            }
                        }  else {
                            detail(mMap, intent, position);
                        }
                    }
                    break;

                case 2:// 设为结束
                    if (msg.arg2 == 1) {
                        if (Integer.valueOf(mList.get(position).get(ScheduleTable.schcRecommendId)) > 0
                                && Integer.valueOf(mList.get(position).get(ScheduleTable.schAID)) == 0) {
                            if (!mList.get(position).get(ScheduleTable.schRepeatID).equals("0")) {
                                sharedPrefUtil.putString(CommonSearchTagActivity.this,
                                        ShareFile.USERFILE,
                                        ShareFile.UPLOADTYPE,
                                        "1");
                            } else {
                                sharedPrefUtil.putString(CommonSearchTagActivity.this,
                                        ShareFile.USERFILE,
                                        ShareFile.UPLOADTYPE,
                                        "0");
                            }
                        } else {
                            sharedPrefUtil.putString(CommonSearchTagActivity.this,
                                    ShareFile.USERFILE,
                                    ShareFile.UPLOADTYPE,
                                    "1");
                        }
                        if (mList.get(position).get(ScheduleTable.schSourceType).toString().equals("3")) {
                            if (mList.get(position).get(ScheduleTable.schpisEnd).toString().equals("0")) {
                                SixNewTaskDialog sixNewTaskDialog = new SixNewTaskDialog(CommonSearchTagActivity.this, R.style.dialog_translucent1,
                                        getWindowManager(), 2, mList.get(position).get(ScheduleTable.schSourceDesc)
                                        , mList.get(position).get(ScheduleTable.schcRecommendId));
                                sixNewTaskDialog.show();
                                sixNewTaskDialog.setCallBack(new SixNewTaskDialog.CallBack() {
                                    @Override
                                    public void NewTaskDialogSure() {
                                        endCalender(mMap);
                                    }

                                    @Override
                                    public void NewTaskDialogCancel() {
                                        commonSearchTagAdapter.notifyDataSetChanged();
                                    }
                                });
                            } else {
                                commonSearchTagAdapter.notifyDataSetChanged();
                            }
                        } else {
                            endCalender(mMap);
                        }
                    } else {
                        if (Integer.valueOf(mList.get(position).get(ScheduleTable.schcRecommendId)) > 0
                                && Integer.valueOf(mList.get(position).get(ScheduleTable.schAID)) == 0) {
                            if (!mList.get(position).get(ScheduleTable.schRepeatID).equals("0")) {
                                sharedPrefUtil.putString(CommonSearchTagActivity.this,
                                        ShareFile.USERFILE,
                                        ShareFile.UPLOADTYPE,
                                        "1");
                                endCalender(mMap);
                            } else {
                                sharedPrefUtil.putString(CommonSearchTagActivity.this, ShareFile.USERFILE, ShareFile.UPLOADTYPE, "0");
                                if (mList.get(position).get(ScheduleTable.schSourceType).toString().equals("3")) {
                                    if (mList.get(position).get(ScheduleTable.schpisEnd).toString().equals("0")) {
                                        SixNewTaskDialog sixNewTaskDialog = new SixNewTaskDialog(CommonSearchTagActivity.this, R.style.dialog_translucent1,
                                                getWindowManager(), 0, mList.get(position).get(ScheduleTable.schSourceDesc)
                                                , mList.get(position).get(ScheduleTable.schcRecommendId));
                                        sixNewTaskDialog.show();
                                        sixNewTaskDialog.setCallBack(new SixNewTaskDialog.CallBack() {
                                            @Override
                                            public void NewTaskDialogSure() {
                                                endCalender(mMap);
                                            }

                                            @Override
                                            public void NewTaskDialogCancel() {
                                                commonSearchTagAdapter.notifyDataSetChanged();
                                            }
                                        });
                                    } else {
                                        commonSearchTagAdapter.notifyDataSetChanged();
                                    }
                                } else {
                                    deleteItem(mMap);
                                }
                            }
                        } else {
                            sharedPrefUtil.putString(CommonSearchTagActivity.this,
                                    ShareFile.USERFILE,
                                    ShareFile.UPLOADTYPE,
                                    "1");
                            endCalender(mMap);
                        }
                    }
                    // adapter.notifyDataSetChanged();
                    break;

                case 3:// 删除
                    if (Integer.valueOf(mList.get(position).get(ScheduleTable.schcRecommendId)) > 0
                            && Integer.valueOf(mList.get(position).get(ScheduleTable.schAID)) == 0) {
                        if (!mList.get(position).get(ScheduleTable.schRepeatID).equals("0")) {
                            sharedPrefUtil.putString(CommonSearchTagActivity.this,
                                    ShareFile.USERFILE,
                                    ShareFile.UPLOADTYPE,
                                    "1");
                        } else {
                            sharedPrefUtil.putString(CommonSearchTagActivity.this,
                                    ShareFile.USERFILE,
                                    ShareFile.UPLOADTYPE,
                                    "0");
                        }
                    } else {
                        sharedPrefUtil.putString(CommonSearchTagActivity.this,
                                ShareFile.USERFILE,
                                ShareFile.UPLOADTYPE,
                                "1");

                    }
                    if (mList.get(position).get(ScheduleTable.schSourceType).toString().equals("3") ||
                            mList.get(position).get(ScheduleTable.schSourceType).toString().equals("4") ||
                            mList.get(position).get(ScheduleTable.schSourceType).toString().equals("5")) {
                        SixNewTaskDialog sixNewTaskDialog = new SixNewTaskDialog(CommonSearchTagActivity.this, R.style.dialog_translucent1,
                                getWindowManager(), mList.get(position).get(ScheduleTable.schSourceType).toString().equals("3") ? 1 : 3,
                                mList.get(position).get(ScheduleTable.schSourceDesc)
                                , mList.get(position).get(ScheduleTable.schcRecommendId));
                        sixNewTaskDialog.show();
                        sixNewTaskDialog.setCallBack(new SixNewTaskDialog.CallBack() {
                            @Override
                            public void NewTaskDialogCancel() {
                                commonSearchTagAdapter.notifyDataSetChanged();
                            }

                            @Override
                            public void NewTaskDialogSure() {
                                deleteCalender(mMap, 0, position);
                            }
                        });
                    } else {
                        alertDeleteDialog(mMap, 0, position);
                    }
                    break;
                case 7://收到的任务更多
                    dialogDetailOnClick(mMap, 0);
                    break;
            }
        }

    };

    private void detail(Map<String, String> mMap, Intent intent, int position ) {
        if (mList.get(position).get(ScheduleTable.schSourceType).toString().equals("3")
                || mList.get(position).get(ScheduleTable.schSourceType).toString().equals("4")
                || mList.get(position).get(ScheduleTable.schSourceType).toString().equals("5")) {
            Intent taskintent = new Intent(CommonSearchTagActivity.this, NewSixTaskDetailActivity.class);
            taskintent.putExtra("ID", mList.get(position).get(ScheduleTable.ID));
            taskintent.putExtra("schID", mList.get(position).get(ScheduleTable.schID));
            taskintent.putExtra("schSourceDesc", mList.get(position).get(ScheduleTable.schSourceDesc));
            taskintent.putExtra("schSourceType", mList.get(position).get(ScheduleTable.schSourceType));
            taskintent.putExtra("schCreateTime", mList.get(position).get(ScheduleTable.schCreateTime));
            taskintent.putExtra("schDate", mList.get(position).get(ScheduleTable.schDate));
            taskintent.putExtra("schTime", mList.get(position).get(ScheduleTable.schTime));
            taskintent.putExtra("schDisplayTime", mList.get(position).get(ScheduleTable.schDisplayTime));
            taskintent.putExtra("schIsPostpone", mList.get(position).get(ScheduleTable.schIsPostpone));
            taskintent.putExtra("schcRecommendName", mList.get(position).get(ScheduleTable.schcRecommendName));
            taskintent.putExtra("schContent", mList.get(position).get(ScheduleTable.schContent));
            taskintent.putExtra("schcRecommendId", mList.get(position).get(ScheduleTable.schcRecommendId));
            taskintent.putExtra("schIsEnd", mList.get(position).get(ScheduleTable.schIsEnd));
            taskintent.putExtra("schImagePath", mList.get(position).get(ScheduleTable.schImagePath));
            taskintent.putExtra("schRemark4", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark4)));
            taskintent.putExtra("schRemark5", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark5)));
            taskintent.putExtra("schRemark1", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark1)));
            startActivityForResult(taskintent, 600);
        } else if (mList.get(position).get(ScheduleTable.schSourceType).toString().equals("2")) {
            if (StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark1)).equals("1")) {
                Intent taskintent = new Intent(CommonSearchTagActivity.this, NewSixTaskDetailActivity.class);
                taskintent.putExtra("ID", mList.get(position).get(ScheduleTable.ID));
                taskintent.putExtra("schID", mList.get(position).get(ScheduleTable.schID));
                taskintent.putExtra("schSourceDesc", mList.get(position).get(ScheduleTable.schSourceDesc));
                taskintent.putExtra("schImagePath", mList.get(position).get(ScheduleTable.schImagePath));
                taskintent.putExtra("schSourceType", mList.get(position).get(ScheduleTable.schSourceType));
                taskintent.putExtra("schCreateTime", mList.get(position).get(ScheduleTable.schCreateTime));
                taskintent.putExtra("schDate", mList.get(position).get(ScheduleTable.schDate));
                taskintent.putExtra("schTime", mList.get(position).get(ScheduleTable.schTime));
                taskintent.putExtra("schDisplayTime", mList.get(position).get(ScheduleTable.schDisplayTime));
                taskintent.putExtra("schIsPostpone", mList.get(position).get(ScheduleTable.schIsPostpone));
                taskintent.putExtra("schcRecommendName", mList.get(position).get(ScheduleTable.schcRecommendName));
                taskintent.putExtra("schContent", mList.get(position).get(ScheduleTable.schContent));
                taskintent.putExtra("schcRecommendId", mList.get(position).get(ScheduleTable.schcRecommendId));
                taskintent.putExtra("schIsEnd", mList.get(position).get(ScheduleTable.schIsEnd));
                taskintent.putExtra("schImagePath", mList.get(position).get(ScheduleTable.schImagePath));
                taskintent.putExtra("schRemark4", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark4)));
                taskintent.putExtra("schRemark5", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark5)));
                taskintent.putExtra("schRemark1", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark1)));
                startActivityForResult(taskintent, 600);
            } else {
                Intent cintent = new Intent(CommonSearchTagActivity.this, CalenderNoteEditActivity.class);
                cintent.putExtra("lingshengnames", mList.get(position).get(ScheduleTable.schRingDesc));
                cintent.putExtra("lingshengcode", mList.get(position).get(ScheduleTable.schRingCode));
                cintent.putExtra("schTime", mList.get(position).get(ScheduleTable.schTime));
                cintent.putExtra("schDate", mList.get(position).get(ScheduleTable.schDate));
                cintent.putExtra("schIsAlarm", mList.get(position).get(ScheduleTable.schIsAlarm));
                cintent.putExtra("schBeforeTime", mList.get(position).get(ScheduleTable.schBeforeTime));
                cintent.putExtra("schDisplayTime", mList.get(position).get(ScheduleTable.schDisplayTime));
                cintent.putExtra("schIsPostpone", mList.get(position).get(ScheduleTable.schIsPostpone));
                cintent.putExtra("content", mList.get(position).get(ScheduleTable.schContent));
                cintent.putExtra("schSourceDesc", mList.get(position).get(ScheduleTable.schSourceDesc));
                cintent.putExtra("schImagePath", mList.get(position).get(ScheduleTable.schImagePath));
                cintent.putExtra("schID", mList.get(position).get(ScheduleTable.schID));
                cintent.putExtra("schIsEnd", mList.get(position).get(ScheduleTable.schIsEnd));
                cintent.putExtra("schRepeatID", mList.get(position).get(ScheduleTable.schRepeatID));
                cintent.putExtra("schRemark1", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark1)));
                startActivityForResult(cintent, 600);
            }
        } else {
            if (Integer.valueOf(mList.get(position).get(ScheduleTable.schcRecommendId)) > 0
                    && Integer.valueOf(mList.get(position).get(ScheduleTable.schAID)) == 0) {
                if (!mList.get(position).get(ScheduleTable.schRepeatID).equals("0")) {
//                                    dialogDetailOnClick(mMap, position);
                    if (StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark1)).equals("1")) {
                        Intent taskintent = new Intent(CommonSearchTagActivity.this, NewSixTaskDetailActivity.class);
                        taskintent.putExtra("ID", mList.get(position).get(ScheduleTable.ID));
                        taskintent.putExtra("schID", mList.get(position).get(ScheduleTable.schID));
                        taskintent.putExtra("schSourceDesc", mList.get(position).get(ScheduleTable.schSourceDesc));
                        taskintent.putExtra("schImagePath", mList.get(position).get(ScheduleTable.schImagePath));
                        taskintent.putExtra("schSourceType", mList.get(position).get(ScheduleTable.schSourceType));
                        taskintent.putExtra("schCreateTime", mList.get(position).get(ScheduleTable.schCreateTime));
                        taskintent.putExtra("schDate", mList.get(position).get(ScheduleTable.schDate));
                        taskintent.putExtra("schTime", mList.get(position).get(ScheduleTable.schTime));
                        taskintent.putExtra("schDisplayTime", mList.get(position).get(ScheduleTable.schDisplayTime));
                        taskintent.putExtra("schIsPostpone", mList.get(position).get(ScheduleTable.schIsPostpone));
                        taskintent.putExtra("schcRecommendName", mList.get(position).get(ScheduleTable.schcRecommendName));
                        taskintent.putExtra("schContent", mList.get(position).get(ScheduleTable.schContent));
                        taskintent.putExtra("schcRecommendId", mList.get(position).get(ScheduleTable.schcRecommendId));
                        taskintent.putExtra("schIsEnd", mList.get(position).get(ScheduleTable.schIsEnd));
                        taskintent.putExtra("schRemark4", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark4)));
                        taskintent.putExtra("schRemark5", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark5)));
                        taskintent.putExtra("schImagePath", mList.get(position).get(ScheduleTable.schImagePath));
                        taskintent.putExtra("schRemark1", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark1)));
                        startActivityForResult(taskintent, 600);
                    } else {
                        Intent cintent = new Intent(CommonSearchTagActivity.this, CalenderNoteEditActivity.class);
                        cintent.putExtra("lingshengnames", mList.get(position).get(ScheduleTable.schRingDesc));
                        cintent.putExtra("lingshengcode", mList.get(position).get(ScheduleTable.schRingCode));
                        cintent.putExtra("schTime", mList.get(position).get(ScheduleTable.schTime));
                        cintent.putExtra("schDate", mList.get(position).get(ScheduleTable.schDate));
                        cintent.putExtra("schIsAlarm", mList.get(position).get(ScheduleTable.schIsAlarm));
                        cintent.putExtra("schBeforeTime", mList.get(position).get(ScheduleTable.schBeforeTime));
                        cintent.putExtra("schDisplayTime", mList.get(position).get(ScheduleTable.schDisplayTime));
                        cintent.putExtra("schIsPostpone", mList.get(position).get(ScheduleTable.schIsPostpone));
                        cintent.putExtra("content", mList.get(position).get(ScheduleTable.schContent));
                        cintent.putExtra("schSourceDesc", mList.get(position).get(ScheduleTable.schSourceDesc));
                        cintent.putExtra("schImagePath", mList.get(position).get(ScheduleTable.schImagePath));
                        cintent.putExtra("schID", mList.get(position).get(ScheduleTable.schID));
                        cintent.putExtra("schIsEnd", mList.get(position).get(ScheduleTable.schIsEnd));
                        cintent.putExtra("schRepeatID", mList.get(position).get(ScheduleTable.schRepeatID));
                        cintent.putExtra("schRemark1", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark1)));
                        startActivityForResult(cintent, 600);
                    }
                } else {
                    if (!mList.get(position).get(ScheduleTable.schSourceDesc).isEmpty()) {
                        App.getDBcApplication().updateReadState(Integer.valueOf(mList.get(position).get(ScheduleTable.schID)), 2);
                        App.getDBcApplication().updateSchSourceDescSpare(mList.get(position).get(ScheduleTable.schID));
                        NoteTitleDetailBean.TDelListBean bean = App.getDBcApplication().getOneNoteTitlesData(userid, mList.get(position).get(ScheduleTable.schSourceDesc), true);
                        if (bean.titles != null) {
                            intent = new Intent(CommonSearchTagActivity.this, NoteEditActivity.class);
                            intent.putExtra("qdlistenter", false);
                            intent.putExtra("titleid", "" + bean.titleId);
                            intent.putExtra("path", "" + bean.imgPath);
                            intent.putExtra("id", bean.id);
                            intent.putExtra("title", bean.titles);
                            intent.putExtra("ltype", bean.ltype + "");
                            intent.putExtra("styles", bean.styles);
                            intent.putExtra("copys", bean.copys);
                            intent.putExtra("remark", bean.remark);
                            intent.putExtra("remark1", bean.remark1);
                            intent.putExtra("openState", bean.openState);
                            intent.putExtra("type", 0);
                            startActivityForResult(intent, 100);
                        } else {
                            Intent intentfx = new Intent(CommonSearchTagActivity.this, QDFXDetailActivity.class);
                            intentfx.putExtra("title", mList.get(position).get(ScheduleTable.schContent));
                            intentfx.putExtra("titleId", mList.get(position).get(ScheduleTable.schSourceDesc));
                            intentfx.putExtra("path", "");
                            intentfx.putExtra("goodNum", "0");
                            intentfx.putExtra("redNum", "0");
                            intentfx.putExtra("name", mList.get(position).get(ScheduleTable.schcRecommendName));
                            intentfx.putExtra("time", mList.get(position).get(ScheduleTable.schCreateTime));
                            intentfx.putExtra("num", "0");
                            if (mMap.get(ScheduleTable.schSourceType).equals("1")) {
                                intentfx.putExtra("type", 5);
                            } else {
                                intentfx.putExtra("type", 2);
                            }
                            intentfx.putExtra("uid", mList.get(position).get(ScheduleTable.schcRecommendId));
                            intentfx.putExtra("stylee", 0);
                            startActivityForResult(intentfx, 100);
                        }
                    } else {

                        updateFrendsPostState(mList.get(position).get(ScheduleTable.schID));
                        Intent intent1 = new Intent(CommonSearchTagActivity.this, FrendLyActivity.class);
                        intent1.putExtra("types", 1);

                        MySchBean mySchBean = new MySchBean();
                        mySchBean.schID = mMap.get(ScheduleTable.schID);
                        mySchBean.schContent = mMap.get(ScheduleTable.schContent);
                        mySchBean.schDate = mMap.get(ScheduleTable.schDate);
                        mySchBean.schTime = mMap.get(ScheduleTable.schTime);
                        mySchBean.schIsAlarm = mMap.get(ScheduleTable.schIsAlarm);
                        mySchBean.schBeforeTime = mMap.get(ScheduleTable.schBeforeTime);
                        mySchBean.schDisplayTime = mMap.get(ScheduleTable.schDisplayTime);
                        mySchBean.schIsPostpone = mMap.get(ScheduleTable.schIsPostpone);
                        mySchBean.schIsImportant = mMap.get(ScheduleTable.schIsImportant);
                        mySchBean.schColorType = mMap.get(ScheduleTable.schColorType);
                        mySchBean.schIsEnd = mMap.get(ScheduleTable.schIsEnd);
                        mySchBean.schCreateTime = mMap.get(ScheduleTable.schCreateTime);
                        mySchBean.schTags = mMap.get(ScheduleTable.schTags);
                        mySchBean.schSourceType = mMap.get(ScheduleTable.schSourceType);
                        mySchBean.schSourceDesc = mMap.get(ScheduleTable.schSourceDesc);
                        mySchBean.schSourceDescSpare = mMap
                                .get(ScheduleTable.schSourceDescSpare);
                        mySchBean.schRepeatID = mMap.get(ScheduleTable.schRepeatID);
                        mySchBean.schRepeatDate = mMap.get(ScheduleTable.schRepeatDate);
                        mySchBean.schUpdateTime = mMap.get(ScheduleTable.schUpdateTime);
                        mySchBean.schUpdateState = mMap.get(ScheduleTable.schUpdateState);
                        mySchBean.schOpenState = mMap.get(ScheduleTable.schOpenState);
                        mySchBean.schRepeatLink = mMap.get(ScheduleTable.schRepeatLink);
                        mySchBean.schRingDesc = mMap.get(ScheduleTable.schRingDesc);
                        mySchBean.schRingCode = mMap.get(ScheduleTable.schRingCode);
                        mySchBean.schcRecommendName = mMap
                                .get(ScheduleTable.schcRecommendName);
                        mySchBean.schRead = mMap.get(ScheduleTable.schRead);
                        intent1.putExtra("bean", mySchBean);
                        intent1.putExtra("schFriendID", mMap.get(ScheduleTable.schcRecommendId));
                        startActivity(intent1);
                    }
                }
            } else {
                if (!mList.get(position).get(ScheduleTable.schSourceDesc).isEmpty()) {
                    App.getDBcApplication().updateReadState(Integer.valueOf(mList.get(position).get(ScheduleTable.schID)), 2);
                    App.getDBcApplication().updateSchSourceDescSpare(mList.get(position).get(ScheduleTable.schID));
                    NoteTitleDetailBean.TDelListBean bean = App.getDBcApplication().getOneNoteTitlesData(userid, mList.get(position).get(ScheduleTable.schSourceDesc), true);
                    if (bean.titles != null) {
                        intent = new Intent(CommonSearchTagActivity.this, NoteEditActivity.class);
                        intent.putExtra("qdlistenter", false);
                        intent.putExtra("titleid", "" + bean.titleId);
                        intent.putExtra("path", "" + bean.imgPath);
                        intent.putExtra("id", bean.id);
                        intent.putExtra("title", bean.titles);
                        intent.putExtra("ltype", bean.ltype + "");
                        intent.putExtra("styles", bean.styles);
                        intent.putExtra("copys", bean.copys);
                        intent.putExtra("remark", bean.remark);
                        intent.putExtra("remark1", bean.remark1);
                        intent.putExtra("openState", bean.openState);
                        intent.putExtra("type", 0);
                        startActivityForResult(intent, 100);
                    } else {
                        Intent intentfx = new Intent(CommonSearchTagActivity.this, QDFXDetailActivity.class);
                        intentfx.putExtra("title", mList.get(position).get(ScheduleTable.schContent));
                        intentfx.putExtra("titleId", mList.get(position).get(ScheduleTable.schSourceDesc));
                        intentfx.putExtra("path", "");
                        intentfx.putExtra("goodNum", "0");
                        intentfx.putExtra("redNum", "0");
                        intentfx.putExtra("name", mList.get(position).get(ScheduleTable.schcRecommendName));
                        intentfx.putExtra("time", mList.get(position).get(ScheduleTable.schCreateTime));
                        intentfx.putExtra("num", "0");
                        intentfx.putExtra("uid", mList.get(position).get(ScheduleTable.schcRecommendId));
                        intentfx.putExtra("stylee", 0);
                        if (mMap.get(ScheduleTable.schSourceType).equals("1")) {
                            intentfx.putExtra("type", 5);
                        } else {
                            intentfx.putExtra("type", 2);
                        }
                        startActivityForResult(intentfx, 100);
                    }
                } else {
//                                    dialogDetailOnClick(mMap, position);
                    if (StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark1)).equals("1")) {
                        Intent taskintent = new Intent(CommonSearchTagActivity.this, NewSixTaskDetailActivity.class);
                        taskintent.putExtra("ID", mList.get(position).get(ScheduleTable.ID));
                        taskintent.putExtra("schID", mList.get(position).get(ScheduleTable.schID));
                        taskintent.putExtra("schSourceDesc", mList.get(position).get(ScheduleTable.schSourceDesc));
                        taskintent.putExtra("schImagePath", mList.get(position).get(ScheduleTable.schImagePath));
                        taskintent.putExtra("schSourceType", mList.get(position).get(ScheduleTable.schSourceType));
                        taskintent.putExtra("schCreateTime", mList.get(position).get(ScheduleTable.schCreateTime));
                        taskintent.putExtra("schDate", mList.get(position).get(ScheduleTable.schDate));
                        taskintent.putExtra("schTime", mList.get(position).get(ScheduleTable.schTime));
                        taskintent.putExtra("schDisplayTime", mList.get(position).get(ScheduleTable.schDisplayTime));
                        taskintent.putExtra("schIsPostpone", mList.get(position).get(ScheduleTable.schIsPostpone));
                        taskintent.putExtra("schcRecommendName", mList.get(position).get(ScheduleTable.schcRecommendName));
                        taskintent.putExtra("schContent", mList.get(position).get(ScheduleTable.schContent));
                        taskintent.putExtra("schcRecommendId", mList.get(position).get(ScheduleTable.schcRecommendId));
                        taskintent.putExtra("schIsEnd", mList.get(position).get(ScheduleTable.schIsEnd));
                        taskintent.putExtra("schRemark4", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark4)));
                        taskintent.putExtra("schRemark5", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark5)));
                        taskintent.putExtra("schImagePath", mList.get(position).get(ScheduleTable.schImagePath));
                        taskintent.putExtra("schRemark1", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark1)));
                        startActivityForResult(taskintent, 600);
                    } else {
                        Intent cintent = new Intent(CommonSearchTagActivity.this, CalenderNoteEditActivity.class);
                        cintent.putExtra("lingshengnames", mList.get(position).get(ScheduleTable.schRingDesc));
                        cintent.putExtra("lingshengcode", mList.get(position).get(ScheduleTable.schRingCode));
                        cintent.putExtra("schTime", mList.get(position).get(ScheduleTable.schTime));
                        cintent.putExtra("schDate", mList.get(position).get(ScheduleTable.schDate));
                        cintent.putExtra("schIsAlarm", mList.get(position).get(ScheduleTable.schIsAlarm));
                        cintent.putExtra("schBeforeTime", mList.get(position).get(ScheduleTable.schBeforeTime));
                        cintent.putExtra("schDisplayTime", mList.get(position).get(ScheduleTable.schDisplayTime));
                        cintent.putExtra("schIsPostpone", mList.get(position).get(ScheduleTable.schIsPostpone));
                        cintent.putExtra("content", mList.get(position).get(ScheduleTable.schContent));
                        cintent.putExtra("schSourceDesc", mList.get(position).get(ScheduleTable.schSourceDesc));
                        cintent.putExtra("schImagePath", mList.get(position).get(ScheduleTable.schImagePath));
                        cintent.putExtra("schID", mList.get(position).get(ScheduleTable.schID));
                        cintent.putExtra("schIsEnd", mList.get(position).get(ScheduleTable.schIsEnd));
                        cintent.putExtra("schRepeatID", mList.get(position).get(ScheduleTable.schRepeatID));
                        cintent.putExtra("schRemark1", StringUtils.getIsStringEqulesNull(mList.get(position).get(ScheduleTable.schRemark1)));
                        startActivityForResult(cintent, 600);
                    }
                }
            }
        }
    }

    private void endCalender(Map<String, String> mMap) {
        if ("0".equals(mMap.get(ScheduleTable.schRepeatID))) {
            updateScheduleRead1(mMap, ScheduleTable.schRead);
        } else {
            updateScheduleRead2(mMap, ScheduleTable.schRead,
                    ScheduleTable.schRepeatLink);
        }
        updateFocusStateSch(mMap, ScheduleTable.schFocusState);
        updateScheduleIsEnd(mMap, ScheduleTable.schIsEnd,
                ScheduleTable.schUpdateState);
        updateSchClock(mMap, LocateAllNoticeTable.isEnd);
        commonSearchTagAdapter.notifyDataSetChanged();
        sharedPrefUtil.putString(CommonSearchTagActivity.this, ShareFile.USERFILE,
                ShareFile.ENDUPDATETIME,
                DateUtil.formatDateTimeSs(new Date()));
        commonSearchTagAdapter.notifyDataSetChanged();
        if (DateUtil.parseDateTime(DateUtil.formatDateTime(new Date())).getTime() >= DateUtil.parseDateTime(
                mMap.get(ScheduleTable.schDate) + " " + mMap.get(ScheduleTable.schTime)).getTime()) {
            QueryAlarmData.writeAlarm(CommonSearchTagActivity.this);
        }
    }

    private void updateRepSchUpdate(Map<String, String> mMap, String key,
                                    String key1) {
        try {
            String value = "0";
            Map<String, String> upMap = new HashMap<String, String>();
            if ("0".equals(mMap.get(key)))
                value = "1";
            else
                value = "0";
            upMap.put(key, value);
            if (!"0".equals(upMap.get(ScheduleTable.schAID))) {
                upMap.put(key1, "1");
            } else {
                upMap.put(key1, "1");
            }
            App.getDBcApplication().updateScheduleData(upMap,
                    "where schID=" + mMap.get("schID"));
            mMap.put(key, value);
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
    }

    private void updateFocusStateSch(Map<String, String> mMap, String key) {
        try {
            Map<String, String> upMap = new HashMap<String, String>();
            upMap.put(key, "1");
            App.getDBcApplication().updateSchFocusState(upMap,
                    "where schID=" + mMap.get("schID"));
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
    }

    private void updateSchedule(Map<String, String> mMap, String key,
                                String key1) {
        String value = "0";
        Map<String, String> upMap = new HashMap<String, String>();
        if ("0".equals(mMap.get(key)))
            value = "1";
        else
            value = "0";
        upMap.put(key, value);
        upMap.put(key1, "2");
        App.getDBcApplication().updateScheduleData(upMap,
                "where schID=" + mMap.get("schID"));
        mMap.put(key, value);
    }

    private void updateScheduleIsEnd(Map<String, String> mMap, String key,
                                     String key1) {
        try {
            if ("1".equals(mMap.get(ScheduleTable.schRepeatLink))
                    || "3".equals(mMap.get(ScheduleTable.schRepeatLink))) {
                repeatSetChildEndUtils.setParentStateIsEnd(mMap);
            }
            String value = "0";
            Map<String, String> upMap = new HashMap<String, String>();
            if ("0".equals(mMap.get(key)))
                value = "1";
            else
                value = "0";
            upMap.put(key, value);
            if ("1".equals(mMap.get(ScheduleTable.schRepeatLink))
                    || "3".equals(mMap.get(ScheduleTable.schRepeatLink))) {
                upMap.put(key1, "0");
            } else {
                upMap.put(key1, "2");
            }
            App.getDBcApplication().updateScheduleData(upMap,
                    "where schID=" + mMap.get("schID"));
            mMap.put(key, value);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void updateSchClock(Map<String, String> mMap, String key) {
        try {
            String value = "0";
            String key1 = "";
            Map<String, String> upMap = new HashMap<String, String>();
            if (key.equals("isEnd")) {
                key1 = "schIsEnd";
            } else if (key.equals("postpone")) {
                key1 = "schIsPostpone";
            }
            if ("1".equals(mMap.get(key1)))
                value = "1";
            else
                value = "0";
            upMap.put(key, value);
            App.getDBcApplication().updateSchIsEnd(upMap,
                    "where schID=" + mMap.get("schID"));
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
    }

    private void updateScheduleRead1(Map<String, String> mMap, String key) {
        try {
            String value = "0";
            Map<String, String> upMap = new HashMap<String, String>();
//            myschedule_listview.hiddenRight();
            // if ("0".equals(mMap.get(key)))
            value = mMap.get(ScheduleTable.schRead);
            // else
            // value = "1";
            upMap.put(key, value);
            App.getDBcApplication().updateScheduleData1(upMap,
                    "where schID=" + mMap.get("schID"));
            mMap.put(key, value);
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
    }

    private void updateScheduleRead2(Map<String, String> mMap, String key,
                                     String key1) {
        try {
            String value = "0";
            Map<String, String> upMap = new HashMap<String, String>();
            // if ("0".equals(mMap.get(key)))
            // value = "0";
            // else
            value = mMap.get(key);
            upMap.put(key, value);
            upMap.put(key1, "3");
            App.getDBcApplication().updateScheduleData(upMap,
                    "where schID=" + mMap.get("schID"));
            mMap.put(key, value);
            mMap.put(key1, "3");
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
    }

    private void deleteCalender(final Map<String, String> mMap,
                                final int type, final int position) {
        if (type == 0) {
            App.getDBcApplication().updateSchReadData(
                    Integer.parseInt(mMap.get(ScheduleTable.schID)), 0);
            App.getDBcApplication().updateSchRepeatLinkData(
                    Integer.parseInt(mMap.get(ScheduleTable.schID)), 2);
            String deleteId = mMap.get(ScheduleTable.schID);
            App dbContextExtended = App.getDBcApplication();

            if (mMap.get(ScheduleTable.schRemark1).equals("1")) {
                dbContextExtended.updateScheduleLocalDataschRemark3(deleteId);
            } else {
                dbContextExtended.deleteScheduleLocalData(deleteId);
            }
            dbContextExtended.deleteSch(Integer.parseInt(deleteId));
            App.getDBcApplication().updateSchReadData(Integer.parseInt(mMap.get(ScheduleTable.schID)), 0);
            loaddata(search_type);
            if (DateUtil.parseDateTime(DateUtil.formatDateTime(new Date())).getTime() >= DateUtil
                    .parseDateTime(mMap.get(ScheduleTable.schDate) + " " + mMap.get(ScheduleTable.schTime)).getTime()) {
                QueryAlarmData.writeAlarm(CommonSearchTagActivity.this);

            }
        }
    }

    private void alertDeleteDialog(final Map<String, String> mMap,
                                   final int type, final int position) {
        final AlertDialog builder = new AlertDialog.Builder(CommonSearchTagActivity.this).create();
        builder.show();
        Window window = builder.getWindow();
        android.view.WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
        params.alpha = 0.92f;
        window.setAttributes(params);// 设置生效
        window.setContentView(R.layout.dialog_alterdelete);
        TextView delete_ok = (TextView) window.findViewById(R.id.delete_ok);
        delete_ok.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                builder.cancel();
                deleteCalender(mMap, type, position);
            }
        });
        TextView delete_canel = (TextView) window
                .findViewById(R.id.delete_canel);
        delete_canel.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                builder.cancel();
            }
        });
        TextView delete_tv = (TextView) window.findViewById(R.id.delete_tv);
        if (type == 0) {
            delete_tv.setText("确定要删除此记事吗?");
        } else {
            delete_tv.setText("结束今天之前所有未结束的记事?");
        }

    }

    /**
     * app日程同步下行修改好友信息和留言
     */
    public void updateFrendsPostState(final String cid) {

        StringRequest stringRequest = new StringRequest(Request.Method.POST, "http://121.40.19.103/timetable/appFrends_updateFrendsPostState.do",
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String result) {
                    }

                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                Log.d("TAG", "error:" + volleyError.toString());
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> map = new HashMap<>();
                map.put("uId", userid);
                map.put("cId", cid);
                return map;
            }
        };
        stringRequest.setTag("findLyNewNum");
        stringRequest.setRetryPolicy(new DefaultRetryPolicy(100000, 1, 1.0f));
        App.queues.add(stringRequest);
    }

    /**
     * 普通记事点击弹出详情菜单 setType 0,菜单详情 1,设置
     *
     * @param
     */
    @SuppressWarnings("deprecation")
    private void dialogDetailOnClick(Map<String, String> mMaps,
                                     final int position) {
        final Dialog dialog = new Dialog(CommonSearchTagActivity.this, R.style.dialog_translucent);
        Window window = dialog.getWindow();
        WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
        params.alpha = 0.92f;
        window.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
        window.setAttributes(params);// 设置生效

        LayoutInflater fac = LayoutInflater.from(CommonSearchTagActivity.this);
        View more_pop_menu = fac.inflate(R.layout.dialog_calender_new_detail, null);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setContentView(more_pop_menu);
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        params.width = CommonSearchTagActivity.this.getWindowManager().getDefaultDisplay().getWidth() - 30;
        dialog.show();

        final Map<String, String> mMap = mMaps;


        List<View> viewList = new ArrayList<View>();


        MyViewPager myViewPager = (MyViewPager) more_pop_menu.findViewById(R.id.viewpager_detail);

        View viewOne = LayoutInflater.from(CommonSearchTagActivity.this).inflate(R.layout.dialog_calender_new_detail_item1, null);
        View viewTwo = LayoutInflater.from(CommonSearchTagActivity.this).inflate(R.layout.dialog_calender_new_detail_item2, null);
//        applyBlur(viewOne);
//        applyBlur(viewTwo);

        final Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        String today = DateUtil.formatDate(calendar.getTime());
        calendar.set(Calendar.DAY_OF_MONTH,
                calendar.get(Calendar.DAY_OF_MONTH) + 1);
        String tomorrow = DateUtil.formatDate(calendar.getTime());

        final int id = Integer.parseInt(mMap.get(ScheduleTable.schID));


        final Map<String, String> map = App.getDBcApplication().QueryStateData(
                Integer.parseInt(mMap.get(ScheduleTable.schRepeatID)));

        final Intent intent = new Intent();

        final MySchBean mySchBean = new MySchBean();
        mySchBean.schID = mMap.get(ScheduleTable.schID);
        mySchBean.schContent = mMap.get(ScheduleTable.schContent);
        mySchBean.schDate = mMap.get(ScheduleTable.schDate);
        mySchBean.schTime = mMap.get(ScheduleTable.schTime);
        mySchBean.schIsAlarm = mMap.get(ScheduleTable.schIsAlarm);
        mySchBean.schBeforeTime = mMap.get(ScheduleTable.schBeforeTime);
        mySchBean.schDisplayTime = mMap.get(ScheduleTable.schDisplayTime);
        mySchBean.schIsPostpone = mMap.get(ScheduleTable.schIsPostpone);
        mySchBean.schIsImportant = mMap.get(ScheduleTable.schIsImportant);
        mySchBean.schColorType = mMap.get(ScheduleTable.schColorType);
        mySchBean.schIsEnd = mMap.get(ScheduleTable.schIsEnd);
        mySchBean.schCreateTime = mMap.get(ScheduleTable.schCreateTime);
        mySchBean.schTags = mMap.get(ScheduleTable.schTags);
        mySchBean.schSourceType = mMap.get(ScheduleTable.schSourceType);
        mySchBean.schSourceDesc = mMap.get(ScheduleTable.schSourceDesc);
        mySchBean.schSourceDescSpare = mMap
                .get(ScheduleTable.schSourceDescSpare);
        mySchBean.schRepeatID = mMap.get(ScheduleTable.schRepeatID);
        mySchBean.schRepeatDate = mMap.get(ScheduleTable.schRepeatDate);
        mySchBean.schUpdateTime = mMap.get(ScheduleTable.schUpdateTime);
        mySchBean.schUpdateState = mMap.get(ScheduleTable.schUpdateState);
        mySchBean.schOpenState = mMap.get(ScheduleTable.schOpenState);
        mySchBean.schRepeatLink = mMap.get(ScheduleTable.schRepeatLink);
        mySchBean.schRingDesc = mMap.get(ScheduleTable.schRingDesc);
        mySchBean.schRingCode = mMap.get(ScheduleTable.schRingCode);
        mySchBean.schcRecommendName = mMap
                .get(ScheduleTable.schcRecommendName);
        mySchBean.schRead = mMap.get(ScheduleTable.schRead);

        /*****第一页****/

//        final ImageView shunyan_image = (ImageView) viewOne.findViewById(R.id.shunyan_image);
//        final TextView shunyan_tv = (TextView) viewOne.findViewById(R.id.shunyan_tv);
//        final ImageView important_image = (ImageView) viewOne.findViewById(R.id.important_image);
//        final TextView important_tv = (TextView) viewOne.findViewById(R.id.important_tv);
//        final ImageView end_image = (ImageView) viewOne.findViewById(R.id.end_image);
//        final TextView end_tv = (TextView) viewOne.findViewById(R.id.end_tv);
//        final TextView bianji = (TextView) viewOne.findViewById(R.id.bianji);
        final TextView fenlei = (TextView) viewOne.findViewById(R.id.fenlei);
//        final TextView date_tv = (TextView) viewOne.findViewById(R.id.date_tv);
//        final TextView time_tv = (TextView) viewOne.findViewById(R.id.time_tv);
        final TextView day = (TextView) viewOne.findViewById(R.id.day);
        final TextView week = (TextView) viewOne.findViewById(R.id.week);
        final TextView month = (TextView) viewOne.findViewById(R.id.month);
        final TextView copy_content = (TextView) viewOne.findViewById(R.id.copy_content);
        final TextView important = (TextView) viewOne.findViewById(R.id.important);
        int colortype = Integer.parseInt(mMap.get(ScheduleTable.schColorType));
        final String colorname = app.QueryTagNameData(colortype).get("ctgText");
        final LinearLayout st_ll = (LinearLayout) viewOne.findViewById(R.id.st_ll);
        final LinearLayout copy_ll = (LinearLayout) viewOne.findViewById(R.id.copy_ll);
        final LinearLayout time_ll = (LinearLayout) viewOne.findViewById(R.id.time_ll);
        final TextView color_tv = viewOne.findViewById(R.id.color_tv);
        if (mMap.get(ScheduleTable.schSourceType).equals("3")
                || mMap.get(ScheduleTable.schSourceType).equals("4")
                || mMap.get(ScheduleTable.schSourceType).equals("5")) {
            copy_ll.setVisibility(View.GONE);
            time_ll.setVisibility(View.GONE);
            st_ll.setVisibility(View.VISIBLE);
        }
        if (colorname.equals("未分类")) {
            fenlei.setText("\"" + colorname + "\"\n分类设置");
        } else {
//            String htmlstr = "<font color='#aaaaaa'>" + colorname + "</font><br>分类设置";
            fenlei.setText("\"" + colorname + "\"\n分类设置");
        }

//        date_tv.setText("\"" + mMap.get(ScheduleTable.schDate) + "\"\n设置日期");
        Today = mMap.get(ScheduleTable.schDate);
//        if (mMap.get(ScheduleTable.schDisplayTime).equals("0")) {
//            time_tv.setText("\"全天\"\n设置时间");
//        } else {
//            time_tv.setText("\"" + mMap.get(ScheduleTable.schTime) + "\"\n设置时间");
//        }

        if (mMap.get(ScheduleTable.schDate).compareTo(DateUtil.nowTodyTime()) <= 0) {
            day.setText("推到明天");
            week.setText("推到下周");
            month.setText("推到下月");
        } else {
            day.setText("推后一天");
            week.setText("推后一周");
            month.setText("推后一月");
        }
        color_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                CalenderColorDialog colorDialog = new CalenderColorDialog(CommonSearchTagActivity.this, R.style.dialog_translucent,
                        getWindowManager(), mMap.get(ScheduleTable.schID), 0);
                colorDialog.show();
                colorDialog.setCallBack(new CalenderColorDialog.CallBack() {
                    @Override
                    public void reminderEditTime(String color_position_f, String color_position) {
                        loaddata(search_type);
                    }
                });
            }
        });
        day.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    updateFocusStateSch(mMap, ScheduleTable.schFocusState);
                    String date = inWeekUtils.AfterOneDay(mMap.get(ScheduleTable.schDate));
                    App.getDBcApplication().updateScheduleDateData(id, date,
                            mMap.get(ScheduleTable.schTime));
                    App.getDBcApplication().updateSchReadData(
                            Integer.parseInt(mMap.get(ScheduleTable.schID)), 0);
                    App.getDBcApplication().updateSchRepeatLinkData(
                            Integer.parseInt(mMap.get(ScheduleTable.schID)), 0);
                    if (!mMap.get(ScheduleTable.schRepeatID).equals("0")) {
//                        App.getDBcApplication().updateSchuledRepeatTo(mMap.get(ScheduleTable.schID));
                    }
                    if ("".equals(mMap.get(ScheduleTable.schRepeatDate))
                            || "0".equals(mMap.get(ScheduleTable.schRepeatLink))) {

                    } else {
                        if (map != null) {
                            String repdate = mMap
                                    .get(ScheduleTable.schRepeatDate);
                            String lastdate = StringUtils.getIsStringEqulesNull(map
                                    .get(CLRepeatTable.repDateOne));
                            String nextdate = StringUtils.getIsStringEqulesNull(map
                                    .get(CLRepeatTable.repDateTwo));
                            repeatSetChildEndUtils.setParentState(Integer.parseInt(mMap
                                    .get(ScheduleTable.schRepeatID)), repdate, nextdate, lastdate, map);
                        }
                    }

                    loaddata(search_type);
                    QueryAlarmData.writeAlarm(CommonSearchTagActivity.this);

                    Intent intentf = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                    Bundle extras = new Bundle();
                    intentf.putExtras(extras);
                    CommonSearchTagActivity.this.sendBroadcast(intentf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                dialog.dismiss();
            }
        });
        week.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    updateFocusStateSch(mMap, ScheduleTable.schFocusState);
                    String date = inWeekUtils.AfterOneWeek(mMap.get(ScheduleTable.schDate));
                    App.getDBcApplication().updateScheduleDateData(id, date,
                            mMap.get(ScheduleTable.schTime));
                    App.getDBcApplication().updateSchReadData(
                            Integer.parseInt(mMap.get(ScheduleTable.schID)), 0);
                    App.getDBcApplication().updateSchRepeatLinkData(
                            Integer.parseInt(mMap.get(ScheduleTable.schID)), 0);
                    if (!mMap.get(ScheduleTable.schRepeatID).equals("0")) {
//                        App.getDBcApplication().updateSchuledRepeatTo(mMap.get(ScheduleTable.schID));
                    }
                    if ("".equals(mMap.get(ScheduleTable.schRepeatDate))
                            || "0".equals(mMap.get(ScheduleTable.schRepeatLink))) {

                    } else {
                        if (map != null) {
                            String repdate = mMap
                                    .get(ScheduleTable.schRepeatDate);
                            String lastdate = StringUtils.getIsStringEqulesNull(map
                                    .get(CLRepeatTable.repDateOne));
                            String nextdate = StringUtils.getIsStringEqulesNull(map
                                    .get(CLRepeatTable.repDateTwo));
                            repeatSetChildEndUtils.setParentState(Integer.parseInt(mMap
                                    .get(ScheduleTable.schRepeatID)), repdate, nextdate, lastdate, map);
                        }
                    }

                    loaddata(search_type);
                    QueryAlarmData.writeAlarm(CommonSearchTagActivity.this);

                    Intent intentf = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                    Bundle extras = new Bundle();
                    intentf.putExtras(extras);
                    CommonSearchTagActivity.this.sendBroadcast(intentf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                dialog.dismiss();
            }
        });
        month.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    updateFocusStateSch(mMap, ScheduleTable.schFocusState);
                    String date = inWeekUtils.AfterOneMonth(mMap.get(ScheduleTable.schDate));
                    App.getDBcApplication().updateScheduleDateData(id, date,
                            mMap.get(ScheduleTable.schTime));
                    App.getDBcApplication().updateSchReadData(
                            Integer.parseInt(mMap.get(ScheduleTable.schID)), 0);
                    App.getDBcApplication().updateSchRepeatLinkData(
                            Integer.parseInt(mMap.get(ScheduleTable.schID)), 0);
                    if (!mMap.get(ScheduleTable.schRepeatID).equals("0")) {
//                        App.getDBcApplication().updateSchuledRepeatTo(mMap.get(ScheduleTable.schID));
                    }
                    if ("".equals(mMap.get(ScheduleTable.schRepeatDate))
                            || "0".equals(mMap.get(ScheduleTable.schRepeatLink))) {

                    } else {
                        if (map != null) {
                            String repdate = mMap
                                    .get(ScheduleTable.schRepeatDate);
                            String lastdate = StringUtils.getIsStringEqulesNull(map
                                    .get(CLRepeatTable.repDateOne));
                            String nextdate = StringUtils.getIsStringEqulesNull(map
                                    .get(CLRepeatTable.repDateTwo));
                            repeatSetChildEndUtils.setParentState(Integer.parseInt(mMap
                                    .get(ScheduleTable.schRepeatID)), repdate, nextdate, lastdate, map);
                        }
                    }

                    loaddata(search_type);

                    QueryAlarmData.writeAlarm(CommonSearchTagActivity.this);

                    Intent intentf = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                    Bundle extras = new Bundle();
                    intentf.putExtras(extras);
                    CommonSearchTagActivity.this.sendBroadcast(intentf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                dialog.dismiss();
            }
        });


//        if ("0".equals(mMap.get(ScheduleTable.schIsPostpone))) {
//            shunyan_image.setBackground(getResources().getDrawable(R.mipmap.anniu_shun_hui));
//            shunyan_tv.setText("自动顺延");
//        } else {
//            shunyan_image.setBackground(getResources().getDrawable(R.mipmap.anniu_shun_lv));
//            shunyan_tv.setText("取消顺延");
//        }

        if ("0".equals(mMap.get(ScheduleTable.schIsImportant))) {
//            important_image.setBackground(getResources().getDrawable(R.mipmap.anniu_zhongyao_hui));
            important.setText("设为重要");
        } else {
//            important_image.setBackground(getResources().getDrawable(R.mipmap.anniu_zhongyao_lv));
            important.setText("取消重要");
        }

//        if ("1".equals(mMap.get(ScheduleTable.schIsEnd))) {
//            end_image.setBackground(getResources().getDrawable(R.mipmap.anniu_jiesu_lv));
//            end_tv.setText("已结束");
//        } else {
//            end_image.setBackground(getResources().getDrawable(R.mipmap.anniu_jiesu_hui));
//            end_tv.setText("未结束");
//        }
//
//        date_tv.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                initRiliDiaLog(date_tv, mMap, false);
//            }
//        });
//
//        time_tv.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                dialog.dismiss();
//                dialogMorningTimeOnClick(time_tv, mMap);
//            }
//        });
//
//        //顺延
//        shunyan_image.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//
//                String date;
//
//                if ("0".equals(mMap.get(ScheduleTable.schIsPostpone))) {
//                    shunyan_image.setBackground(getResources().getDrawable(R.mipmap.anniu_shun_lv));
//                    shunyan_tv.setText("取消顺延");
//                } else {
//                    shunyan_image.setBackground(getResources().getDrawable(R.mipmap.anniu_shun_hui));
//                    shunyan_tv.setText("自动顺延");
//                }
//                updateSchedule(mMap, ScheduleTable.schIsPostpone,
//                        ScheduleTable.schUpdateState);
//                updateSchClock(mMap, LocateAllNoticeTable.postpone);
//                updateFocusStateSch(mMap, ScheduleTable.schFocusState);
//                calendar.setTime(DateUtil.parseDate(mMap
//                        .get(ScheduleTable.schDate)));
//                if (DateUtil.parseDate(mMap.get(ScheduleTable.schDate)).before(
//                        DateUtil.parseDate(DateUtil.formatDate(new Date())))) {
//                    calendar.set(Calendar.DAY_OF_MONTH,
//                            calendar.get(Calendar.DAY_OF_MONTH) + 1);
//                    date = DateUtil.formatDate(calendar.getTime());
//                    App.getDBcApplication().updateScheduleDateData(id, date,
//                            mMap.get(ScheduleTable.schTime));
//                }
//
//                App.getDBcApplication().updateSchReadData(
//                        Integer.parseInt(mMap.get(ScheduleTable.schID)), 0);
//                App.getDBcApplication().updateSchRepeatLinkData(
//                        Integer.parseInt(mMap.get(ScheduleTable.schID)), 0);
//                if (!mMap.get(ScheduleTable.schRepeatID).equals("0")) {
//                    App.getDBcApplication().updateSchuledRepeatTo(mMap.get(ScheduleTable.schID));
//                }
//                if ("".equals(mMap.get(ScheduleTable.schRepeatDate))
//                        || "0".equals(mMap.get(ScheduleTable.schRepeatLink))) {
//
//                } else {
//                    if (map != null) {
//                        String repdate = mMap
//                                .get(ScheduleTable.schRepeatDate);
//                        String lastdate = StringUtils.getIsStringEqulesNull(map
//                                .get(CLRepeatTable.repDateOne));
//                        String nextdate = StringUtils.getIsStringEqulesNull(map
//                                .get(CLRepeatTable.repDateTwo));
//                        repeatSetChildEndUtils.setParentState(Integer.parseInt(mMap
//                                .get(ScheduleTable.schRepeatID)), repdate, nextdate, lastdate, map);
//                    }
//                }
//                loaddata(search_type);
//                QueryAlarmData.writeAlarm(CommonSearchTagActivity.this);
//            }
//        });

        //重要
        important.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if ("0".equals(mMap.get(ScheduleTable.schIsImportant))) {
//                    important_image.setBackground(getResources().getDrawable(R.mipmap.anniu_zhongyao_lv));
                    important.setText("取消重要");
                } else {
//                    important_image.setBackground(getResources().getDrawable(R.mipmap.anniu_zhongyao_hui));
                    important.setText("设为重要");
                }
                try {
                    updateFocusStateSch(mMap, ScheduleTable.schFocusState);
                    App.getDBcApplication().updateSchReadData(
                            Integer.parseInt(mMap.get(ScheduleTable.schID)), 0);
                    App.getDBcApplication().updateSchRepeatLinkData(
                            Integer.parseInt(mMap.get(ScheduleTable.schID)), 0);
                    if (!"".equals(mMap.get(ScheduleTable.schRepeatDate))
                            && !"0".equals(mMap
                            .get(ScheduleTable.schRepeatLink))) {
                        if (map != null) {
                            String repdate = mMap
                                    .get(ScheduleTable.schRepeatDate);
                            String lastdate = StringUtils.getIsStringEqulesNull(map
                                    .get(CLRepeatTable.repDateOne));
                            String nextdate = StringUtils.getIsStringEqulesNull(map
                                    .get(CLRepeatTable.repDateTwo));
                            repeatSetChildEndUtils.setParentState(Integer.parseInt(mMap
                                    .get(ScheduleTable.schRepeatID)), repdate, nextdate, lastdate, map);
                        }
                        updateRepSchUpdate(mMap, ScheduleTable.schIsImportant,
                                ScheduleTable.schUpdateState);
                    } else {
                        updateSchedule(mMap, ScheduleTable.schIsImportant,
                                ScheduleTable.schUpdateState);
                    }
                    loaddata(search_type);
                    QueryAlarmData.writeAlarm(CommonSearchTagActivity.this);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                dialog.dismiss();

            }
        });
//
//        //结束
//        end_image.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if ("1".equals(mMap.get(ScheduleTable.schIsEnd))) {
//                    end_image.setBackground(getResources().getDrawable(R.mipmap.anniu_jiesu_hui));
//                    end_tv.setText("未结束");
//                } else {
//                    end_image.setBackground(getResources().getDrawable(R.mipmap.anniu_jiesu_lv));
//                    end_tv.setText("已结束");
//                }
//                if (Integer.valueOf(mMap.get(ScheduleTable.schcRecommendId)) > 0
//                        && Integer.valueOf(mMap.get(ScheduleTable.schAID)) == 0) {
//                    if (!mMap.get(ScheduleTable.schRepeatID).equals("0")) {
//                        sharedPrefUtil.putString(CommonSearchTagActivity.this,
//                                ShareFile.USERFILE,
//                                ShareFile.UPLOADTYPE,
//                                "1");
//                        endCalender(mMap);
//                    } else {
//                        sharedPrefUtil.putString(CommonSearchTagActivity.this,
//                                ShareFile.USERFILE,
//                                ShareFile.UPLOADTYPE,
//                                "0");
//                        deleteItem(mMap);
//                    }
//
//                } else {
//                    sharedPrefUtil.putString(CommonSearchTagActivity.this,
//                            ShareFile.USERFILE,
//                            ShareFile.UPLOADTYPE,
//                            "1");
//                    endCalender(mMap);
//                }
//
//
//                if ("1".equals(mMap.get(ScheduleTable.schRepeatLink))
//                        || "3".equals(mMap.get(ScheduleTable.schRepeatLink))) {
//                    repeatSetChildEndUtils.setParentStateIsEnd(mMap);
//                }
//                String value = "0";
//                if ("0".equals(mMap.get(ScheduleTable.schIsEnd)))
//                    value = "1";
//                else
//                    value = "0";
//                mMap.put(ScheduleTable.schIsEnd, value);
//                if ("1".equals(mMap.get(ScheduleTable.schRepeatLink))
//                        || "3".equals(mMap.get(ScheduleTable.schRepeatLink))) {
//                    mMap.put(ScheduleTable.schUpdateState, "0");
//                } else {
//                    mMap.put(ScheduleTable.schUpdateState, "2");
//                }
//                loaddata(search_type);
//                dialog.dismiss();
//
//                Intent intentf = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
//                Bundle extras = new Bundle();
//                intentf.putExtras(extras);
//                CommonSearchTagActivity.this.sendBroadcast(intentf);
//            }
//        });
//
//        //编辑
//        bianji.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                CalenderEditContentDialog calenderEditContentDialog = new CalenderEditContentDialog(CommonSearchTagActivity.this,
//                        R.style.dialog_translucent, getWindowManager(), mMap);
//                calenderEditContentDialog.show();
//                calenderEditContentDialog.setCallBack(new CalenderEditContentDialog.CallBack() {
//                    @Override
//                    public void reminderEditTime() {
//                        loaddata(search_type);
//                    }
//                });
//                dialog.dismiss();
//            }
//        });

        //分类
        fenlei.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    CalenderFlagDialog calenderFlagDialog = new CalenderFlagDialog(CommonSearchTagActivity.this, R.style.dialog_translucent,
                            getWindowManager(), mMap.get(ScheduleTable.schID), colorname, "");
                    calenderFlagDialog.setCallBack(new CalenderFlagDialog.CallBack() {
                        @Override
                        public void reminderEditTime(String name, String id) {
                            loaddata(search_type);
                        }
                    });
                    calenderFlagDialog.show();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                dialog.dismiss();
            }
        });


        /*****第二页****/
        final TextView copy_one = (TextView) viewTwo.findViewById(R.id.copy_one);
        TextView delete = (TextView) viewTwo.findViewById(R.id.delete);
        TextView shitinglings = (TextView) viewTwo.findViewById(R.id.shitinglings);
//        TextView zhaunfaweixin = (TextView) viewTwo.findViewById(R.id.zhaunfaweixin);
//        TextView zhaunfahaoyou = (TextView) viewTwo.findViewById(R.id.zhaunfahaoyou);
//        TextView copy_calender = (TextView) viewTwo.findViewById(R.id.copy_calender);
//        TextView copy_content = (TextView) viewTwo.findViewById(R.id.copy_content);
//        TextView top = (TextView) viewTwo.findViewById(R.id.top);
//        final TextView wanchengrenwu = (TextView) viewTwo.findViewById(R.id.wanchengrenwu);
//        LinearLayout top_ll = (LinearLayout) viewTwo.findViewById(R.id.top_ll);
//        LinearLayout lings_ll = (LinearLayout) viewTwo.findViewById(R.id.lings_ll);
//        final TextView tixingshijain = (TextView) viewTwo.findViewById(R.id.tixingshijain);
//        TextView add_note = (TextView) viewTwo.findViewById(R.id.add_note);
//
//        wanchengrenwu.setText("\"" + mMap.get(ScheduleTable.schRingDesc) + "\"\n铃声设置");
//
//
//        if (mMap.get(ScheduleTable.schDisplayTime).equals("0")
//                && mMap.get(ScheduleTable.schIsPostpone).equals("1")) {
//            top_ll.setVisibility(View.VISIBLE);
//            lings_ll.setVisibility(View.GONE);
//        } else {
//            top_ll.setVisibility(View.GONE);
//            lings_ll.setVisibility(View.VISIBLE);
//        }
//
//
//        String beforeStr = "\"一次提醒\"";
//
//        if (Integer.valueOf(mMap.get(ScheduleTable.schIsAlarm)) == 0 || Integer.valueOf(mMap.get(ScheduleTable.schIsAlarm)) == 1) {
//            beforeStr = "\"一次提醒\"";
//            beforeType = "准时提醒";
//            isAlarm = 1;
//            //有提前
//        } else if (Integer.valueOf(mMap.get(ScheduleTable.schIsAlarm)) == 2) {
//            isAlarm = 2;
//            beforeStr = "\"一次提醒\"";
//            if (Integer.valueOf(mMap.get(ScheduleTable.schBeforeTime)) == 5) {
//                beforeType = "提前5分钟";
//            } else if (Integer.valueOf(mMap.get(ScheduleTable.schBeforeTime)) == 15) {
//                beforeType = "提前15分钟";
//            } else if (Integer.valueOf(mMap.get(ScheduleTable.schBeforeTime)) == 30) {
//                beforeType = "提前30分钟";
//            } else if (Integer.valueOf(mMap.get(ScheduleTable.schBeforeTime)) == 60) {
//                beforeType = "提前1小时";
//            } else if (Integer.valueOf(mMap.get(ScheduleTable.schBeforeTime)) == 120) {
//                beforeType = "提前2小时";
//            } else if (Integer.valueOf(mMap.get(ScheduleTable.schBeforeTime)) == 24 * 60) {
//                beforeType = "提前1天";
//            } else if (Integer.valueOf(mMap.get(ScheduleTable.schBeforeTime)) == 48 * 60) {
//                beforeType = "提前2天";
//            } else if (Integer.valueOf(mMap.get(ScheduleTable.schBeforeTime)) == 7 * 24 * 60) {
//                beforeType = "提前1周";
//            }
//            //准时+提前
//        } else if (Integer.valueOf(mMap.get(ScheduleTable.schIsAlarm)) == 3) {
//            isAlarm = 3;
//            beforeStr = "\"两次提醒\"";
//            if (Integer.valueOf(mMap.get(ScheduleTable.schBeforeTime)) == 5) {
//                beforeType = "准时提醒\n提前5分钟";
//            } else if (Integer.valueOf(mMap.get(ScheduleTable.schBeforeTime)) == 15) {
//                beforeType = "准时提醒\n提前15分钟";
//            } else if (Integer.valueOf(mMap.get(ScheduleTable.schBeforeTime)) == 30) {
//                beforeType = "准时提醒\n提前30分钟";
//            } else if (Integer.valueOf(mMap.get(ScheduleTable.schBeforeTime)) == 60) {
//                beforeType = "准时提醒\n提前1小时";
//            } else if (Integer.valueOf(mMap.get(ScheduleTable.schBeforeTime)) == 120) {
//                beforeType = "准时提醒\n提前2小时";
//            } else if (Integer.valueOf(mMap.get(ScheduleTable.schBeforeTime)) == 24 * 60) {
//                beforeType = "准时提醒\n提前1天";
//            } else if (Integer.valueOf(mMap.get(ScheduleTable.schBeforeTime)) == 48 * 60) {
//                beforeType = "准时提醒\n提前2天";
//            } else if (Integer.valueOf(mMap.get(ScheduleTable.schBeforeTime)) == 7 * 24 * 60) {
//                beforeType = "准时提醒\n提前1周";
//            }
//        }
//        tixingshijain.setText(beforeStr);
//        initValues(Integer.valueOf(mMap.get(ScheduleTable.schIsAlarm)));
//
        delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    if (Integer.valueOf(mList.get(position).get(ScheduleTable.schcRecommendId)) > 0
                            && Integer.valueOf(mList.get(position).get(ScheduleTable.schAID)) == 0) {
                        sharedPrefUtil.putString(CommonSearchTagActivity.this,
                                ShareFile.USERFILE,
                                ShareFile.UPLOADTYPE,
                                "0");
                    } else {
                        sharedPrefUtil.putString(CommonSearchTagActivity.this,
                                ShareFile.USERFILE,
                                ShareFile.UPLOADTYPE,
                                "1");

                    }
                    alertDeleteDialog(mMap, 0, position);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                Intent intentd = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                Bundle extrasd = new Bundle();
                intentd.putExtras(extrasd);
                CommonSearchTagActivity.this.sendBroadcast(intentd);
                dialog.dismiss();
            }
        });


        try {
            fileDescriptor = getAssets().openFd(mMap.get(ScheduleTable.schRingCode) + ".mp3");
            mediaPlayer.setDataSource(
                    fileDescriptor.getFileDescriptor(),
                    fileDescriptor.getStartOffset(),
                    fileDescriptor.getLength());
            mediaPlayer.prepare();
        } catch (Exception e) {
            e.printStackTrace();
        }
        st_ll.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mediaPlayer != null && mediaPlayer.isPlaying()) {
                    mediaPlayer.stop();
                    mediaPlayer.reset();
                    try {
                        AssetFileDescriptor fileDescriptor = getAssets().openFd(
                                mMap.get(ScheduleTable.schRingCode)
                                        + ".mp3");
                        mediaPlayer.setDataSource(
                                fileDescriptor.getFileDescriptor(),
                                fileDescriptor.getStartOffset(),
                                fileDescriptor.getLength());
                        mediaPlayer.prepare();
                        mediaPlayer.start();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else {
                    mediaPlayer.start();
                }
            }
        });
        //试听铃声
        shitinglings.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mediaPlayer != null && mediaPlayer.isPlaying()) {
                    mediaPlayer.stop();
                    mediaPlayer.reset();
                    try {
                        AssetFileDescriptor fileDescriptor = getAssets().openFd(
                                mMap.get(ScheduleTable.schRingCode)
                                        + ".mp3");
                        mediaPlayer.setDataSource(
                                fileDescriptor.getFileDescriptor(),
                                fileDescriptor.getStartOffset(),
                                fileDescriptor.getLength());
                        mediaPlayer.prepare();
                        mediaPlayer.start();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                } else {
                    mediaPlayer.start();
                }

            }
        });
//
//        //转发微信
//        zhaunfaweixin.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                ShareSDK.initSDK(CommonSearchTagActivity.this);
//                OnekeyShare oks = new OnekeyShare();
//                // 关闭sso授权
//                oks.disableSSOWhenAuthorize();
//                oks.setText(mySchBean.schDate + "  " + mySchBean.schTime + "  " + mySchBean.schContent);
//                // 启动分享GUI
//                oks.show(CommonSearchTagActivity.this);
//                dialog.dismiss();
//            }
//        });
//        //转发好友
//        zhaunfahaoyou.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (sharedPrefUtil.getString(CommonSearchTagActivity.this,
//                        ShareFile.USERFILE, ShareFile.ISNEWYOUKE, "-1").equals("-1")) {
//                    intent.putExtra("bean", mySchBean);
//                    startActivity(intent.setClass(CommonSearchTagActivity.this, SchZhuanFaActivity.class));
//                    dialog.dismiss();
//                } else {
//                    startActivity(new Intent(CommonSearchTagActivity.this, NewResiginActivity.class));
//                    dialog.dismiss();
//                }
//            }
//        });
//        //置顶
//        top.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                App.getDBcApplication().updateSceduleDataTop(mMap.get(ScheduleTable.schID), DateUtil.nowTimes(), DateUtil.nowTodyTime());
//                loaddata(search_type);
//                QueryAlarmData.writeAlarm(CommonSearchTagActivity.this);
//
//                Intent intentappwidget = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
//                Bundle extras = new Bundle();
//                intentappwidget.putExtras(extras);
//                CommonSearchTagActivity.this.sendBroadcast(intentappwidget);
//                dialog.dismiss();
//            }
//        });
//        //复制日程
//        copy_calender.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                initRiliDiaLog(date_tv, mMap, true);
//                dialog.dismiss();
//            }
//        });
        //复制文本
        copy_content.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ClipboardManager cm = (ClipboardManager) CommonSearchTagActivity.this.getSystemService(CommonSearchTagActivity.this.CLIPBOARD_SERVICE);
                // 将文本内容放到系统剪贴板里。
                cm.setText(mMap.get(ScheduleTable.schContent));
                Toast.makeText(CommonSearchTagActivity.this, "已复制", Toast.LENGTH_SHORT).show();
                dialog.dismiss();
            }
        });
        copy_one.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ClipboardManager cm = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
                // 将文本内容放到系统剪贴板里。
                cm.setText(mMap.get(ScheduleTable.schContent));
                initRiliDiaLog(copy_one, mMap, true);
                dialog.dismiss();
            }
        });
        //选择铃声
//        wanchengrenwu.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                CalenderRingDialog calenderRingDialog = new CalenderRingDialog(CommonSearchTagActivity.this,
//                        R.style.dialog_translucent, getWindowManager(), mMap.get(ScheduleTable.schID), mMap.get(ScheduleTable.schRepeatID));
//                calenderRingDialog.setCallBack(new CalenderRingDialog.CallBack() {
//                    @Override
//                    public void reminderEditTime(String lingshengname, String code) {
//                        mMap.put(ScheduleTable.schRingDesc, lingshengname);
//                        mMap.put(ScheduleTable.schRingCode, code);
//                        wanchengrenwu.setText("\"" + mMap.get(ScheduleTable.schRingDesc) + "\"\n铃声设置");
//                        try {
//                            mediaPlayer.reset();
//                            fileDescriptor = getAssets().openFd(
//                                    mMap.get(ScheduleTable.schRingCode)
//                                            + ".mp3");
//                            mediaPlayer.setDataSource(
//                                    fileDescriptor.getFileDescriptor(),
//                                    fileDescriptor.getStartOffset(),
//                                    fileDescriptor.getLength());
//                            mediaPlayer.prepare();
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                        }
//                        loaddata(search_type);
//                    }
//                });
//                calenderRingDialog.show();
//            }
//        });
//        //提醒时间
//        tixingshijain.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (mMap.get(ScheduleTable.schDisplayTime).equals("0")) {
//                    Toast.makeText(CommonSearchTagActivity.this, "全天日程不能设置提前提醒时间", Toast.LENGTH_SHORT).show();
//                } else {
//                    initBeforeDiaLog(tixingshijain, mMap, beforeType);
//                }
//
//            }
//        });
//        //加入清单
//        add_note.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                CalenderNoteDialog calenderNoteDialog = new CalenderNoteDialog(CommonSearchTagActivity.this,
//                        R.style.dialog_translucent, getWindowManager(), mMap.get(ScheduleTable.schDate).substring(5) + " " + mMap.get(ScheduleTable.schTime) + " " + mMap.get(ScheduleTable.schContent), "");
//                calenderNoteDialog.show();
//                dialog.dismiss();
//            }
//        });
//
        final ImageView yd1 = (ImageView) more_pop_menu.findViewById(R.id.yd1);
        final ImageView yd2 = (ImageView) more_pop_menu.findViewById(R.id.yd2);

        viewList.add(viewOne);

        if (!mMap.get(ScheduleTable.schSourceType).equals("3")
                && !mMap.get(ScheduleTable.schSourceType).equals("4")
                && !mMap.get(ScheduleTable.schSourceType).equals("5")) {
            viewList.add(viewTwo);
        } else {
            yd1.setVisibility(View.GONE);
            yd2.setVisibility(View.GONE);
        }

        ViewAdapter viewAdapter = new ViewAdapter(viewList);
        myViewPager.setAdapter(viewAdapter);


        myViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (!mMap.get(ScheduleTable.schSourceType).equals("3")
                        && !mMap.get(ScheduleTable.schSourceType).equals("4")
                        && !mMap.get(ScheduleTable.schSourceType).equals("5")) {
                    yd1.setBackground(getResources().getDrawable(R.drawable.calender_new_detail_yd1));
                    yd2.setBackground(getResources().getDrawable(R.drawable.calender_new_detail_yd1));
                    if (position == 0) {
                        yd1.setBackground(getResources().getDrawable(R.drawable.calender_new_detail_yd2));
                    }
                    if (position == 1) {
                        yd2.setBackground(getResources().getDrawable(R.drawable.calender_new_detail_yd2));
                    }
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }


    private void dialogMorningTimeOnClick(TextView time_tv, Map<String, String> mMap) {
        Dialog dialog = new Dialog(CommonSearchTagActivity.this, R.style.dialog_translucent);
        Window window = dialog.getWindow();
        android.view.WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
        params.alpha = 0.92f;
        window.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
        window.setAttributes(params);// 设置生效

        LayoutInflater fac = LayoutInflater.from(CommonSearchTagActivity.this);
        View more_pop_menu = fac.inflate(R.layout.dialog_gundong_time, null);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setContentView(more_pop_menu);
        params.height = android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
        params.width = getWindowManager().getDefaultDisplay().getWidth();
        dialog.show();
        new TimeOnClick(dialog, more_pop_menu, time_tv, mMap);
    }

    class TimeOnClick {

        private View view;
        private Dialog dialog;
        // private PickerView hour_pv;
        // private PickerView minute_pv;
        CycleWheelView hour_cy;
        CycleWheelView min_cy;
        String hour;
        String minute;
        private String timeSet = "";
        private TextView time_tv;

        Map<String, String> mMap;
        ToggleButton toggleButton;

        @SuppressLint("NewApi")
        public TimeOnClick(Dialog dialog, View view, TextView time_tv, Map<String, String> mMap) {
            this.dialog = dialog;
            this.view = view;
            this.time_tv = time_tv;
            this.mMap = mMap;
            timeSet = mMap.get(ScheduleTable.schTime);
            initview();
            initdata();
        }

        private void initview() {
            hour_cy = (CycleWheelView) view.findViewById(R.id.hour_cy);
            min_cy = (CycleWheelView) view.findViewById(R.id.min_cy);

//            view.findViewById(R.id.bp).setOnClickListener(new OnClickListener() {
//                @Override
//                public void onClick(View v) {
//                    dialog.dismiss();
//                    initDiaLog(time_tv, mMap);
//                }
//            });

            toggleButton = (ToggleButton) view.findViewById(R.id.toggle);
            if (mMap.get(ScheduleTable.schDisplayTime).equals("0")) {
                toggleButton.setChecked(true);
            } else {
                toggleButton.setChecked(false);
            }
            toggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView,
                                             boolean isChecked) {
                    if (isChecked) {
                        // 选中
                        int schID = App.getDBcApplication().getLocalId(-1, "ScheduleTable", ScheduleTable.schID);
                        sharedPrefUtil.putString(CommonSearchTagActivity.this, ShareFile.USERFILE, ShareFile.SCHID, schID + "");
                        App.getDBcApplication().updateSceduleDataTime(mMap.get(ScheduleTable.schID), mMap.get(ScheduleTable.schTime), 0);


                        if (!mMap.get(ScheduleTable.schRepeatID).equals("0")) {
                            App.getDBcApplication().updateSchuledRepeatTo(mMap.get(ScheduleTable.schID));
                        }
                        loaddata(search_type);
                        QueryAlarmData.writeAlarm(CommonSearchTagActivity.this);

                        Intent intentappwidget = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                        Bundle extras = new Bundle();
                        intentappwidget.putExtras(extras);
                        sendBroadcast(intentappwidget);
                    } else {
                        // 未选中
                        int schID1 = App.getDBcApplication().getLocalId(-1, "ScheduleTable", ScheduleTable.schID);
                        sharedPrefUtil.putString(CommonSearchTagActivity.this, ShareFile.USERFILE,
                                ShareFile.SCHID, schID1 + "");
                        App.getDBcApplication().updateSceduleDataTime(mMap.get(ScheduleTable.schID), timeSet, 1);

                        if (!mMap.get(ScheduleTable.schRepeatID).equals("0")) {
                            App.getDBcApplication().updateSchuledRepeatTo(mMap.get(ScheduleTable.schID));
                        }
                        loaddata(search_type);
                        QueryAlarmData.writeAlarm(CommonSearchTagActivity.this);

                        Intent intentappwidget1 = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                        Bundle extras1 = new Bundle();
                        intentappwidget1.putExtras(extras1);
                        sendBroadcast(intentappwidget1);
                    }
                }
            });
        }

        private void initdata() {
            int curHours = Integer.parseInt(timeSet.split(":")[0]);
            int curMinutes = Integer.parseInt(timeSet.split(":")[1]);
            hour = curHours + "";
            minute = curMinutes + "";
            int currentHoursIndex = 0;
            int currentMinutesIndex = 0;
            List<String> hours = new ArrayList<String>();
            List<String> minutes = new ArrayList<String>();
            for (int i = 0; i < 24; i++) {
                hours.add(i < 10 ? "0" + i : "" + i);

            }
            for (int i = 0; i < 60; i++) {
                minutes.add(i < 10 ? "0" + i : "" + i);
            }
            for (int i = 0; i < hours.size(); i++) {
                if (curHours == Integer.parseInt(hours.get(i))) {
                    currentHoursIndex = i;
                }
            }
            for (int i = 0; i < minutes.size(); i++) {
                if (curMinutes == Integer.parseInt(minutes.get(i))) {
                    currentMinutesIndex = i;
                }
            }
            hour_cy.setLabels(hours);
            try {
                hour_cy.setWheelSize(5);
            } catch (CycleWheelView.CycleWheelViewException e) {
                e.printStackTrace();
            }
            hour_cy.setCycleEnable(true);
            hour_cy.setSelection(currentHoursIndex);
            hour_cy.setAlphaGradual(0.6f);
            hour_cy.setDivider(getResources().getColor(R.color.gongkai_txt), 1);
            hour_cy.setSolid(Color.WHITE, Color.WHITE);
            hour_cy.setLabelColor(getResources().getColor(R.color.gongkai_txt));
            hour_cy.setLabelSelectColor(Color.BLACK);
            hour_cy.setOnWheelItemSelectedListener(new CycleWheelView.WheelItemSelectedListener() {
                @Override
                public void onItemSelected(int position, String label) {
                    hour = Integer.parseInt(label) < 10 ? "0"
                            + Integer.parseInt(label) : label;
                    minute = Integer.parseInt(minute) < 10 ? "0"
                            + Integer.parseInt(minute) : minute;
                    int schID1 = App.getDBcApplication().getLocalId(-1, "ScheduleTable", ScheduleTable.schID);
                    sharedPrefUtil.putString(CommonSearchTagActivity.this, ShareFile.USERFILE, ShareFile.SCHID, schID1 + "");
                    if (!timeSet.equals(hour + ":" + minute)) {
                        toggleButton.setChecked(false);
                    }
                    timeSet = hour + ":" + minute;
                    App.getDBcApplication().updateSceduleDataTime(mMap.get(ScheduleTable.schID), timeSet, toggleButton.isChecked() ? 0 : 1);

                    if (!mMap.get(ScheduleTable.schRepeatID).equals("0")) {
                        App.getDBcApplication().updateSchuledRepeatTo(mMap.get(ScheduleTable.schID));
                    }
                    loaddata(search_type);
                    QueryAlarmData.writeAlarm(CommonSearchTagActivity.this);

                    Intent intentappwidget1 = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                    Bundle extras1 = new Bundle();
                    intentappwidget1.putExtras(extras1);
                    sendBroadcast(intentappwidget1);
                }
            });

            min_cy.setLabels(minutes);
            try {
                min_cy.setWheelSize(5);
            } catch (CycleWheelView.CycleWheelViewException e) {
                e.printStackTrace();
            }
            min_cy.setCycleEnable(true);
            min_cy.setSelection(currentMinutesIndex);
            min_cy.setAlphaGradual(0.6f);
            min_cy.setDivider(getResources().getColor(R.color.gongkai_txt), 1);
            min_cy.setSolid(Color.WHITE, Color.WHITE);
            min_cy.setLabelColor(getResources().getColor(R.color.gongkai_txt));
            min_cy.setLabelSelectColor(Color.BLACK);
            min_cy.setOnWheelItemSelectedListener(new CycleWheelView.WheelItemSelectedListener() {
                @Override
                public void onItemSelected(int position, String label) {
                    hour = Integer.parseInt(hour) < 10 ? "0"
                            + Integer.parseInt(hour) : hour;
                    minute = Integer.parseInt(label) < 10 ? "0"
                            + Integer.parseInt(label) : label;
                    int schID1 = App.getDBcApplication().getLocalId(-1, "ScheduleTable", ScheduleTable.schID);
                    sharedPrefUtil.putString(CommonSearchTagActivity.this, ShareFile.USERFILE, ShareFile.SCHID, schID1 + "");
                    if (!timeSet.equals(hour + ":" + minute)) {
                        toggleButton.setChecked(false);
                    }
                    timeSet = hour + ":" + minute;
                    App.getDBcApplication().updateSceduleDataTime(mMap.get(ScheduleTable.schID), timeSet, toggleButton.isChecked() ? 0 : 1);

                    if (!mMap.get(ScheduleTable.schRepeatID).equals("0")) {
                        App.getDBcApplication().updateSchuledRepeatTo(mMap.get(ScheduleTable.schID));
                    }
                    loaddata(search_type);
                    QueryAlarmData.writeAlarm(CommonSearchTagActivity.this);

                    Intent intentappwidget1 = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                    Bundle extras1 = new Bundle();
                    intentappwidget1.putExtras(extras1);
                    sendBroadcast(intentappwidget1);
                }
            });
        }
    }

    String beforeType;
    final MediaPlayer mediaPlayer = new MediaPlayer();
    AssetFileDescriptor fileDescriptor;

    private void initDiaLog(TextView time_tv, Map<String, String> mMap) {
        Dialog dialog = new Dialog(CommonSearchTagActivity.this, R.style.dialog_translucent);
        Window window = dialog.getWindow();
        WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
        params.alpha = 0.92f;
        window.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
        window.setAttributes(params);// 设置生效

        LayoutInflater fac = LayoutInflater.from(CommonSearchTagActivity.this);
        View more_pop_menu = fac.inflate(R.layout.dialog_calender_time, null);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setContentView(more_pop_menu);
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        params.width = CommonSearchTagActivity.this.getWindowManager().getDefaultDisplay().getWidth();
        dialog.show();

        new MyClick(dialog, more_pop_menu, time_tv, mMap);
    }

    class MyClick implements View.OnClickListener {

        private Dialog dialog;
        private RelativeLayout rela_hour;
        private RelativeLayout rela_minutes;
        private int hours = 12;
        private int minutes = 0;
        private int width;
        private int centerX;
        private int centerY;
        private Calendar calendar;
        private int lastMinutes;
        private TextView dialog_tv_state, dialog_tv_state1;
        private int grState;// 结果为0是上午 结果为1是下午
        private String chooseHour;
        private String chooseMinute;

        private TextView tv_clock_state;
        private LinearLayout ll_clock, state_ll;
        private TextView tv_clock_time;
        private TextView tv_clock_beforetime;
        private TextView time_tv, tv_gt;

        private RelativeLayout date_re;
        Map<String, String> mMap;
        String time;

        private MyClick(final Dialog dialog, View more_pop_menu, TextView time_tvs, final Map<String, String> mMap) {
            this.dialog = dialog;
            this.time_tv = time_tvs;
            this.mMap = mMap;
            time = mMap.get(ScheduleTable.schTime);
            calendar = Calendar.getInstance();
            // if (isNeedPush) {
            String[] times;

            if ("全天".equals(time)) {
                times = sharedPrefUtil.getString(CommonSearchTagActivity.this, ShareFile.USERFILE,
                        ShareFile.ALLTIME, "08:58").split(":");
            } else {
                times = time.split(":");
            }
            calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(times[0]));
            calendar.set(Calendar.MINUTE, Integer.parseInt(times[1]));
            // }
            rela_hour = (RelativeLayout) more_pop_menu
                    .findViewById(R.id.rela_hour);
            rela_minutes = (RelativeLayout) more_pop_menu
                    .findViewById(R.id.rela_minutes);

            dialog_tv_state = (TextView) more_pop_menu
                    .findViewById(R.id.dialog_tv_state);
            date_re = (RelativeLayout) more_pop_menu
                    .findViewById(R.id.date_re);
            dialog_tv_state1 = (TextView) more_pop_menu
                    .findViewById(R.id.dialog_tv_state1);
            state_ll = (LinearLayout) more_pop_menu
                    .findViewById(R.id.state_ll);
            state_ll.setOnClickListener(this);
            tv_clock_state = (TextView) more_pop_menu
                    .findViewById(R.id.tv_clock_state);
            tv_clock_state.setOnClickListener(this);
            ll_clock = (LinearLayout) more_pop_menu.findViewById(R.id.ll_clock);
            ll_clock.setOnClickListener(this);
            more_pop_menu.findViewById(R.id.tv_gt).setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    dialog.dismiss();
                    dialogMorningTimeOnClick(time_tv, mMap);
                }
            });

            tv_clock_time = (TextView) more_pop_menu
                    .findViewById(R.id.tv_clock_time);
            tv_clock_beforetime = (TextView) more_pop_menu
                    .findViewById(R.id.tv_clock_beforetime);

            width = CommonSearchTagActivity.this.getWindowManager().getDefaultDisplay().getWidth();
            int haf = Utils.dipTopx(CommonSearchTagActivity.this, 40) / 2;
            centerX = width / 2 - Utils.dipTopx(CommonSearchTagActivity.this, 16);
            centerY = width / 2 - Utils.dipTopx(CommonSearchTagActivity.this, 16) - haf;

            initclockValue();
            initHour();
            initMinutes();

            grState = calendar.get(Calendar.AM_PM);
//            if (grState == 0) {// 结果为0是上午 结果为1是下午
//                dialog_tv_state.setText("上午");
//            } else {
//                dialog_tv_state.setText("下午");
//            }
            if (grState == 1) {// 上午
                dialog_tv_state1.setTextColor(Color.parseColor("#08f0ff"));
                dialog_tv_state1.setTextSize(30);
                dialog_tv_state.setTextColor(Color.parseColor("#aaaaaa"));
                dialog_tv_state.setTextSize(14);
                grState = 1;
                calendar.set(Calendar.AM_PM, grState);
            } else if (grState == 0) {// 下午
                dialog_tv_state.setTextColor(Color.parseColor("#08f0ff"));
                dialog_tv_state.setTextSize(30);
                dialog_tv_state1.setTextColor(Color.parseColor("#aaaaaa"));
                dialog_tv_state1.setTextSize(14);
                grState = 0;
                calendar.set(Calendar.AM_PM, grState);
            }
        }

        private void initclockValue() {
            tv_clock_time.setText(time);
            if (time.split(":")[0].substring(0, 1).equals("0")) {
                if (Integer.valueOf(time.split(":")[0].substring(1, time.split(":")[0].length())) >= 0 &&
                        Integer.valueOf(time.split(":")[0].substring(1, time.split(":")[0].length())) <= 6) {
                    tv_clock_time.setText("凌晨 " + time);
                }
            }
        }

        private void initHour() {
            int hour = calendar.get(Calendar.HOUR);
            if (hour == 0) {
                hour = 12;
            }
            int hourRadius = Utils.dipTopx(CommonSearchTagActivity.this, 90); // 设置圆半径
            for (int i = 12; i >= 1; i--) {
                int dy = (int) (hourRadius * Math.cos((Math.PI / 6.0) * i));
                int dx = (int) (hourRadius * Math.sin((Math.PI / 6.0) * i));

                int x1 = centerX + dx;
                int y1 = centerY - dy;

                String text = hours < 10 ? "0" + hours : "" + hours;

                TextView textView = new TextView(CommonSearchTagActivity.this);
                textView.setText(text);
                textView.setTextColor(Color.WHITE);
                textView.setTextSize(18.0f);
                textView.setGravity(Gravity.CENTER);
                textView.setLayoutParams(new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.WRAP_CONTENT,
                        LinearLayout.LayoutParams.WRAP_CONTENT));
                textView.setTag(i);
                textView.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        chooseHour = v.getTag().toString();
                        chageHour(Integer.parseInt(chooseHour));
                        calendar.set(Calendar.HOUR,
                                Integer.parseInt(chooseHour));
                        calendar.set(Calendar.MINUTE,
                                Integer.parseInt(chooseMinute));
                        if (grState == 0) {// 上午
                            calendar.set(Calendar.AM_PM, 0);
                        } else if (grState == 1) {// 下午
                            calendar.set(Calendar.AM_PM, 1);
                        }
                        String calendarHour = calendar
                                .get(Calendar.HOUR_OF_DAY) < 10 ? "0"
                                + calendar.get(Calendar.HOUR_OF_DAY) : ""
                                + calendar.get(Calendar.HOUR_OF_DAY);
                        String calendarMinute = calendar.get(Calendar.MINUTE) < 10 ? "0"
                                + calendar.get(Calendar.MINUTE)
                                : "" + calendar.get(Calendar.MINUTE);
                        time_tv.setText("\"" + calendarHour + ":" + calendarMinute + "\"\n设置时间");
                        tv_clock_time.setText(((0 <= calendar
                                .get(Calendar.HOUR_OF_DAY) && calendar
                                .get(Calendar.HOUR_OF_DAY) <= 6) ? "凌晨" : "") + calendarHour + ":" + calendarMinute);

                        App.getDBcApplication().updateSceduleDataTime(mMap.get(ScheduleTable.schID), calendarHour + ":" + calendarMinute, 1);
                        if (!mMap.get(ScheduleTable.schRepeatID).equals("0")) {
                            App.getDBcApplication().updateSchuledRepeatTo(mMap.get(ScheduleTable.schID));
                        }
                        loaddata(search_type);
                        QueryAlarmData.writeAlarm(CommonSearchTagActivity.this);

                        Intent intentappwidget = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                        Bundle extras = new Bundle();
                        intentappwidget.putExtras(extras);
                        CommonSearchTagActivity.this.sendBroadcast(intentappwidget);

                    }
                });

                if (hour == i) {
                    chooseHour = text;
                    textView.setTextColor(Color.WHITE);
                    textView.setBackgroundResource(R.mipmap.icon_shuzi1);
                } else {
                    textView.setBackgroundDrawable(null);
                }

                rela_hour.addView(textView);

                textView.setAnimation(animTranslate(centerX, centerY, x1, y1,
                        textView, 200));

                hours--;
            }
        }

        private void initMinutes() {
            int minute = calendar.get(Calendar.MINUTE);
            int result = minute % 5;
            if (result != 0) {
                int division = minute / 5;
                minute = division * 5;
            }
            int minutesRadius = Utils.dipTopx(CommonSearchTagActivity.this, 140); // 设置圆半径
            for (int i = 0; i < 12; i++) {
                int dy = (int) (minutesRadius * Math.cos((Math.PI / 6.0) * i));
                int dx = (int) (minutesRadius * Math.sin((Math.PI / 6.0) * i));

                int x1 = centerX + dx;
                int y1 = centerY - dy;

                String text = minutes * 5 < 10 ? "0" + minutes * 5 : ""
                        + minutes * 5;

                TextView textView = new TextView(CommonSearchTagActivity.this);
                textView.setText(text);
                textView.setTextColor(Color.WHITE);
                textView.setTextSize(18.0f);
                textView.setGravity(Gravity.CENTER);
                textView.setLayoutParams(new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.WRAP_CONTENT,
                        LinearLayout.LayoutParams.WRAP_CONTENT));
                textView.setTag(text);
                textView.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        chooseMinute = v.getTag().toString();
                        chageMinutes(Integer.parseInt(chooseMinute) / 5);
                        lastMinutes = Integer.parseInt(chooseMinute) / 5;
                        calendar.set(Calendar.HOUR,
                                Integer.parseInt(chooseHour));
                        calendar.set(Calendar.MINUTE,
                                Integer.parseInt(chooseMinute));
                        if (grState == 0) {// 上午
                            calendar.set(Calendar.AM_PM, 0);
                        } else if (grState == 1) {// 下午
                            calendar.set(Calendar.AM_PM, 1);
                        }
                        String calendarHour = calendar
                                .get(Calendar.HOUR_OF_DAY) < 10 ? "0"
                                + calendar.get(Calendar.HOUR_OF_DAY) : ""
                                + calendar.get(Calendar.HOUR_OF_DAY);
                        String calendarMinute = calendar.get(Calendar.MINUTE) < 10 ? "0"
                                + calendar.get(Calendar.MINUTE)
                                : "" + calendar.get(Calendar.MINUTE);
                        time_tv.setText("\"" + calendarHour + ":" + calendarMinute + "\"\n设置时间");
                        tv_clock_time.setText(((0 <= calendar
                                .get(Calendar.HOUR_OF_DAY) && calendar
                                .get(Calendar.HOUR_OF_DAY) <= 6) ? "凌晨" : "") + calendarHour + ":" + calendarMinute);
                        App.getDBcApplication().updateSceduleDataTime(mMap.get(ScheduleTable.schID), calendarHour + ":" + calendarMinute, 1);
                        if (!mMap.get(ScheduleTable.schRepeatID).equals("0")) {
                            App.getDBcApplication().updateSchuledRepeatTo(mMap.get(ScheduleTable.schID));
                        }
                        loaddata(search_type);
                        QueryAlarmData.writeAlarm(CommonSearchTagActivity.this);

                        Intent intentappwidget = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                        Bundle extras = new Bundle();
                        intentappwidget.putExtras(extras);
                        CommonSearchTagActivity.this.sendBroadcast(intentappwidget);
                    }
                });
                if (minute == Integer.parseInt(text)) {
                    lastMinutes = i;
                    chooseMinute = text;
                    textView.setTextColor(Color.WHITE);
                    textView.setBackgroundResource(R.mipmap.icon_shuzi2);
                } else {
                    textView.setBackgroundDrawable(null);
                }
                rela_minutes.addView(textView);
                textView.setAnimation(animTranslate(centerX, centerY, x1, y1,
                        textView, 200));

                minutes++;
            }
        }

        private void chageHour(int hours) {
            for (int i = rela_hour.getChildCount() - 1; i >= 0; i--) {
                TextView tv_hour = (TextView) rela_hour.getChildAt(i);
                if (hours == Integer.parseInt(tv_hour.getTag().toString())) {
                    tv_hour.setBackgroundResource(R.mipmap.icon_shuzi1);
                } else {
                    tv_hour.setBackgroundDrawable(null);
                }
            }
        }

        private void chageMinutes(int minutes) {
            TextView textView = (TextView) rela_minutes.getChildAt(lastMinutes);
            textView.setBackgroundDrawable(null);
            TextView tv_minutes = (TextView) rela_minutes.getChildAt(minutes);
            tv_minutes.setBackgroundResource(R.mipmap.icon_shuzi2);
        }


        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.state_ll:
                    calendar.set(Calendar.HOUR, Integer.parseInt(chooseHour));
                    calendar.set(Calendar.MINUTE, Integer.parseInt(chooseMinute));
                    if (grState == 0) {// 上午
                        dialog_tv_state1.setTextColor(Color.parseColor("#08f0ff"));
                        dialog_tv_state1.setTextSize(30);
                        dialog_tv_state.setTextColor(Color.parseColor("#aaaaaa"));
                        dialog_tv_state.setTextSize(14);
                        grState = 1;
                        calendar.set(Calendar.AM_PM, grState);
                    } else if (grState == 1) {// 下午
                        dialog_tv_state.setTextColor(Color.parseColor("#08f0ff"));
                        dialog_tv_state.setTextSize(30);
                        dialog_tv_state1.setTextColor(Color.parseColor("#aaaaaa"));
                        dialog_tv_state1.setTextSize(14);
                        grState = 0;
                        calendar.set(Calendar.AM_PM, grState);
                    }
//                    dialog_tv_state.startAnimation(AnimationUtils.loadAnimation(
//                            CommonSearchTagActivity.this, R.anim.scale_in));
                    String calendarHour = calendar.get(Calendar.HOUR_OF_DAY) < 10 ? "0"
                            + calendar.get(Calendar.HOUR_OF_DAY)
                            : "" + calendar.get(Calendar.HOUR_OF_DAY);
                    String calendarMinute = calendar.get(Calendar.MINUTE) < 10 ? "0"
                            + calendar.get(Calendar.MINUTE)
                            : "" + calendar.get(Calendar.MINUTE);
                    time_tv.setText("\"" + calendarHour + ":" + calendarMinute + "\"\n设置时间");
                    tv_clock_time.setText(((0 <= calendar
                            .get(Calendar.HOUR_OF_DAY) && calendar
                            .get(Calendar.HOUR_OF_DAY) <= 6) ? "凌晨" : "") + calendarHour + ":" + calendarMinute);

                    App.getDBcApplication().updateSceduleDataTime(mMap.get(ScheduleTable.schID), calendarHour + ":" + calendarMinute, 1);
                    if (!mMap.get(ScheduleTable.schRepeatID).equals("0")) {
                        App.getDBcApplication().updateSchuledRepeatTo(mMap.get(ScheduleTable.schID));
                    }
                    loaddata(search_type);
                    QueryAlarmData.writeAlarm(CommonSearchTagActivity.this);

                    Intent intentappwidget1 = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                    Bundle extras1 = new Bundle();
                    intentappwidget1.putExtras(extras1);
                    CommonSearchTagActivity.this.sendBroadcast(intentappwidget1);
//                    dialog.dismiss();
                    break;

                case R.id.tv_clock_state:
                    // isNeedPush = false;
                    time_tv.setText("\"全天\"\n设置时间");
                    // tv_beforetime.setText("");
                    dialog.dismiss();
                    App.getDBcApplication().updateSceduleDataTime(mMap.get(ScheduleTable.schID), mMap.get(ScheduleTable.schTime), 0);
                    if (!mMap.get(ScheduleTable.schRepeatID).equals("0")) {
                        App.getDBcApplication().updateSchuledRepeatTo(mMap.get(ScheduleTable.schID));
                    }
                    loaddata(search_type);
                    QueryAlarmData.writeAlarm(CommonSearchTagActivity.this);

                    Intent intentappwidget = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                    Bundle extras = new Bundle();
                    intentappwidget.putExtras(extras);
                    CommonSearchTagActivity.this.sendBroadcast(intentappwidget);

//                    dialog.dismiss();
                    break;

                case R.id.ll_clock:
//                    if (date_re.getVisibility() == View.VISIBLE){
//                        date_re.setVisibility(View.GONE);
//                        time_ll.setVisibility(View.VISIBLE);
//                    }else {
//                        date_re.setVisibility(View.VISIBLE);
//                        time_ll.setVisibility(View.GONE);
//                    }
                    break;

                default:
                    dialog.dismiss();

                    break;
            }
        }

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        loaddata(search_type);
        super.onActivityResult(requestCode, resultCode, data);
    }

    private Animation animationTranslate;
    private RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(0, 0);

    // 移动的动画效果
    /*
     * TranslateAnimation(float fromXDelta, float toXDelta, float
	 * fromYDelta,float toYDelta)
	 *
	 * float fromXDelta:这个参数表示动画开始的点离当前View X坐标上的差值；
	 *
	 * float toXDelta, 这个参数表示动画结束的点离当前View X坐标上的差值；
	 *
	 * float fromYDelta, 这个参数表示动画开始的点离当前View Y坐标上的差值；
	 *
	 * float toYDelta)这个参数表示动画开始的点离当前View Y坐标上的差值；
	 */
    protected Animation animTranslate(float toX, float toY, final int x1,
                                      final int y1, final TextView textView, long durationMillis) {
        animationTranslate = new TranslateAnimation(toX, toX, toY, toY);
        animationTranslate.setAnimationListener(new Animation.AnimationListener() {

            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                params = new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.WRAP_CONTENT,
                        RelativeLayout.LayoutParams.WRAP_CONTENT);
                params.setMargins(x1, y1, 0, 0);
                textView.setLayoutParams(params);
                textView.setPadding(12, 7, 12, 7);
                textView.clearAnimation();
            }
        });
        animationTranslate.setDuration(durationMillis);
        return animationTranslate;
    }

    private void initValues(int setBefore) {
        if (setBefore == 0) {
            indexti = 0;
        } else if (setBefore == 5) {
            indexti = 1;
        } else if (setBefore == 15) {
            indexti = 2;
        } else if (setBefore == 30) {
            indexti = 3;
        } else if (setBefore == 60) {
            indexti = 4;
        } else if (setBefore == 120) {
            indexti = 5;
        } else if (setBefore == 24 * 60) {
            indexti = 6;
        } else if (setBefore == 48 * 60) {
            indexti = 7;
        } else if (setBefore == 7 * 24 * 60) {
            indexti = 8;
        }
    }


    /******日历*****/
    int[] solartime = new int[25];
    boolean isLeap = false;
    boolean isRed = false;
    ArrayList<HashMap<String, String>> data;
    String today;
    int temp_day;
    int temp_month;
    int temp_year;

    int to_day;
    int to_month;
    int to_year;
    int standard_day;
    int standard_month;
    int standard_year;
    String holiday = "";
    String curDate = "";

    int sourse;//
    String dateTime = "";// 日期
    private TextView title;

    MyLinearLayout dataLinear;
    Handler handlerrili;
    LinearLayout.LayoutParams mLayoutParamss = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT);

    private void initRiliDiaLog(final TextView date_tv, final Map<String, String> mMap, final boolean isCopyCalender) {
        final Dialog dialog = new Dialog(CommonSearchTagActivity.this, R.style.dialog_translucent);
        Window window = dialog.getWindow();
        WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
        window.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
        window.setAttributes(params);// 设置生效

        LayoutInflater fac = LayoutInflater.from(CommonSearchTagActivity.this);
        View more_pop_menu = fac.inflate(R.layout.dialog_calender_rili, null);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setContentView(more_pop_menu);
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        params.width = CommonSearchTagActivity.this.getWindowManager().getDefaultDisplay().getWidth();
        dialog.show();

        curDate = dateTime;

        dataLinear = (MyLinearLayout) more_pop_menu.findViewById(R.id.datalinear);
        title = (TextView) more_pop_menu.findViewById(R.id.title);
        dataLinear.setBackgroundColor(Color.WHITE);
        more_pop_menu.findViewById(R.id.lastmonth).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (standard_month == 1) {
                    standard_month = 12;
                    standard_year--;
                } else {
                    standard_month--;
                }
                GenData(false, curDate);
                GenView();
                title.setText(standard_year + "年" + standard_month + "月");
                dataLinear.startAnimation(AnimationUtils.loadAnimation(CommonSearchTagActivity.this, R.anim.right_in));

            }
        });
        more_pop_menu.findViewById(R.id.nextmonth).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (standard_month == 12) {
                    standard_month = 1;
                    standard_year++;
                } else {
                    standard_month++;
                }
                GenData(false, curDate);
                GenView();
                title.setText(standard_year + "年" + standard_month + "月");
                dataLinear.startAnimation(AnimationUtils.loadAnimation(CommonSearchTagActivity.this, R.anim.left_in));

            }
        });
        handlerrili = new Handler() {
            public void handleMessage(Message msg) {
                if (msg == null) {
                    return;
                }
                switch (msg.what) {
                    case 0:
                        if (standard_month == 1) {
                            standard_month = 12;
                            standard_year--;
                        } else {
                            standard_month--;
                        }
                        GenData(false, curDate);
                        GenView();
                        title.setText(standard_year + "年" + standard_month + "月");
                        dataLinear.startAnimation(AnimationUtils.loadAnimation(CommonSearchTagActivity.this, R.anim.right_in));
                        break;

                    case 1:
                        if (standard_month == 12) {
                            standard_month = 1;
                            standard_year++;
                        } else {
                            standard_month++;
                        }
                        GenData(false, curDate);
                        GenView();
                        title.setText(standard_year + "年" + standard_month + "月");
                        dataLinear.startAnimation(AnimationUtils.loadAnimation(CommonSearchTagActivity.this, R.anim.left_in));
                        break;

                    case 2:
                        standard_year--;
                        GenData(false, curDate);
                        GenView();
                        title.setText(standard_year + "年" + standard_month + "月");
                        dataLinear.startAnimation(AnimationUtils.loadAnimation(CommonSearchTagActivity.this, R.anim.down_in));
                        break;

                    case 3:
                        standard_year++;
                        GenData(false, curDate);
                        GenView();
                        title.setText(standard_year + "年" + standard_month + "月");
                        dataLinear.startAnimation(AnimationUtils.loadAnimation(CommonSearchTagActivity.this, R.anim.up_in));
                        break;

                    case 9:
                        date_tv.setText(msg.obj + "");

                        if (isCopyCalender) {
//                            int schID = App.getDBcApplication().getLocalId(-1, "ScheduleTable", ScheduleTable.schID);
//                            sharedPrefUtil.putString(CommonSearchTagActivity.this, ShareFile.USERFILE, ShareFile.SCHID, schID + "");
//                            App.getDBcApplication().insertScheduleData(mMap.get(ScheduleTable.schContent), (msg.obj + "").split("\n")[0].replace("\"", ""),
//                                    DateUtil.nowTimes(), 1,
//                                    Integer.parseInt(mMap.get(ScheduleTable.schBeforeTime)), Integer.valueOf(mMap.get(ScheduleTable.schDisplayTime)),
//                                    Integer.valueOf(mMap.get(ScheduleTable.schIsPostpone)), 0,
//                                    Integer.valueOf(mMap.get(ScheduleTable.schColorType)), 0, DateUtil.formatDateTime(new Date()),
//                                    mMap.get(ScheduleTable.schTags), Integer.valueOf(mMap.get(ScheduleTable.schSourceType)),
//                                    "", "", 0, "", DateUtil.formatDateTime(new Date()),
//                                    1, 0, 0, mMap.get(ScheduleTable.schRingCode), mMap.get(ScheduleTable.schRingDesc), "", 0, 0, 0, "",
//                                    "", 0, 0, 0);
//
//                            Toast.makeText(CommonSearchTagActivity.this, "清单创建成功,", Toast.LENGTH_LONG).show();
                            App.getDBcApplication().copyCalnederNoteData(userid,
                                    mMap.get(ScheduleTable.schID),
                                    mMap.get(ScheduleTable.schSourceDesc),
                                    msg.obj.toString());
                            Toast.makeText(CommonSearchTagActivity.this, "已复制", Toast.LENGTH_SHORT).show();
                        } else {
                            App.getDBcApplication().updateSceduleDataDate(mMap.get(ScheduleTable.schID), (msg.obj + "").split("\n")[0]);
                            if (!mMap.get(ScheduleTable.schRepeatID).equals("0")) {
                                App.getDBcApplication().updateSchuledRepeatTo(mMap.get(ScheduleTable.schID));
                            }
                        }
                        loaddata(search_type);
                        QueryAlarmData.writeAlarm(CommonSearchTagActivity.this);
                        Intent intentappwidget = new Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
                        Bundle extras = new Bundle();
                        intentappwidget.putExtras(extras);
                        sendBroadcast(intentappwidget);
                        dialog.dismiss();
                        break;

                    case 11:
                        Toast.makeText(CommonSearchTagActivity.this, "网络中断", Toast.LENGTH_LONG).show();
                        break;

                    case 12:
                        Toast.makeText(CommonSearchTagActivity.this, "服务器错误", Toast.LENGTH_LONG).show();
                        break;
                }
            }
        };
        dataLinear.setHandler(handlerrili);


        new LoadDataAsyncTask().execute();


    }

    class LoadDataAsyncTask extends AsyncTask<Void, Void, Void> {

        @Override
        protected Void doInBackground(Void... params) {
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
//			dialog.dismiss();
            GenData(true, curDate);
            GenView();
        }

    }

    public ArrayList<HashMap<String, String>> GenData(boolean isfirst, String date) {
        if (!date.equals("") && isfirst) {
            data = new ArrayList<HashMap<String, String>>();
            to_year = Integer.parseInt(date.split("-")[0].toString());
            to_month = Integer.parseInt(date.split("-")[1].toString());
            to_day = Integer.parseInt(date.split("-")[2].toString());
            temp_day = to_day;
            temp_month = to_month;
            temp_year = to_year;
            standard_day = to_day;
            standard_month = to_month;
            standard_year = to_year;
            today = date;
            title.setText(standard_year + "年" + standard_month + "月");
        } else {
            if (isfirst) {
                data = new ArrayList<HashMap<String, String>>();
                Calendar c = Calendar.getInstance();
                c.setTimeInMillis(System.currentTimeMillis());
                to_year = c.get(Calendar.YEAR);
                to_month = c.get(Calendar.MONTH);
                to_day = c.get(Calendar.DAY_OF_MONTH);

                to_month++;
                temp_day = to_day;
                temp_month = to_month;
                temp_year = to_year;
                standard_day = to_day;
                standard_month = to_month;
                standard_year = to_year;

                today = to_year + "-"
                        + (to_month > 9 ? "" + to_month : "0" + to_month) + "-"
                        + (to_day > 9 ? "" + to_day : "0" + to_day);
                title.setText(standard_year + "年" + standard_month + "月");
            } else {
                data = new ArrayList<HashMap<String, String>>();
                temp_day = standard_day;
                temp_month = standard_month;
                temp_year = standard_year;

            }
        }
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("day", temp_day + "");

        map.put("isMonth", "1"); // 1是本月
        String tempStrT = temp_year + "-"
                + (temp_month > 9 ? "" + temp_month : "0" + temp_month) + "-"
                + (temp_day > 9 ? "" + temp_day : "0" + temp_day);
        if ("".equals(StringUtils.getIsStringEqulesNull(tempStrT))) {
            tempStrT = today;
        }
        if (today.equals(tempStrT)) {
            map.put("isToday", "1"); // 1是今天
            map.put("time", today);
        } else {
            map.put("isToday", "0"); // 1是今天
            map.put("time", tempStrT);
        }
        try {
            if (CalHoliday(Integer.valueOf(temp_month
                    + (temp_day > 9 ? "" + temp_day : "0" + temp_day)))) {
                map.put("lunar", holiday);
            } else {
                map.put("lunar", CalendarChange.CalendarChange(tempStrT));
            }
            if (isRed) {
                map.put("isHoliday", "1"); // 1节日
                isRed = false;
            } else {
                map.put("isHoliday", "0"); // 1节日
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        data.add(map);
        for (int i = temp_day - 1; i > 0; i--) {
            String tempStr = temp_year + "-"
                    + (temp_month > 9 ? "" + temp_month : "0" + temp_month)
                    + "-" + (i > 9 ? "" + i : "0" + i);
            map = new HashMap<String, String>();
            map.put("day", i + "");
            map.put("time", tempStr);
            map.put("isToday", "0"); // 1是今天
            map.put("isMonth", "1"); // 1是本月
            try {
                if (CalHoliday(Integer.valueOf("" + temp_month
                        + (i > 9 ? "" + i : "0" + i)))) {
                    map.put("lunar", holiday);
                } else {
                    map.put("lunar", CalendarChange.CalendarChange(tempStr));
                }
                if (isRed) {
                    map.put("isHoliday", "1"); // 1节日
                    isRed = false;
                } else {
                    map.put("isHoliday", "0"); // 1节日
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            data.add(0, map);
        }
        int te_week = calWeek(temp_year, temp_month, 1);
        if (temp_month == 1) {
            temp_year--;
            temp_month = 12;
        } else {
            temp_month--;
        }
        calLeapYear(temp_year);
        if (temp_month == 4 || temp_month == 6 || temp_month == 9
                || temp_month == 11) {
            for (int i = 30; i > 30 - te_week; i--) {
                String tempStr = temp_year + "-"
                        + (temp_month > 9 ? "" + temp_month : "0" + temp_month)
                        + "-" + (i > 9 ? "" + i : "0" + i);
                map = new HashMap<String, String>();
                map.put("day", i + "");
                map.put("time", tempStr);
                map.put("isToday", "0"); // 是今天
                map.put("isMonth", "0"); // 1是本月
                try {
                    if (CalHoliday(Integer.valueOf("" + temp_month
                            + (i > 9 ? "" + i : "0" + i)))) {
                        map.put("lunar", holiday);
                    } else {
                        map.put("lunar", CalendarChange.CalendarChange(tempStr));
                    }
                    if (isRed) {
                        map.put("isHoliday", "1"); // 1节日
                        isRed = false;
                    } else {
                        map.put("isHoliday", "0"); // 1节日
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                data.add(0, map);
            }
        } else if (temp_month == 2) {
            if (isLeap) {
                for (int i = 29; i > 29 - te_week; i--) {
                    String tempStr = temp_year
                            + "-"
                            + (temp_month > 9 ? "" + temp_month : "0"
                            + temp_month) + "-"
                            + (i > 9 ? "" + i : "0" + i);
                    map = new HashMap<String, String>();
                    map.put("day", i + "");
                    map.put("time", tempStr);
                    map.put("isToday", "0"); // 1是今天
                    map.put("isMonth", "0"); // 1是本月
                    try {
                        if (CalHoliday(Integer.valueOf("" + temp_month
                                + (i > 9 ? "" + i : "0" + i)))) {
                            map.put("lunar", holiday);
                        } else {
                            map.put("lunar",
                                    CalendarChange.CalendarChange(tempStr));
                        }
                        if (isRed) {
                            map.put("isHoliday", "1"); // 1节日
                            isRed = false;
                        } else {
                            map.put("isHoliday", "0"); // 1节日
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    data.add(0, map);
                }
            } else {
                for (int i = 28; i > 28 - te_week; i--) {
                    String tempStr = temp_year
                            + "-"
                            + (temp_month > 9 ? "" + temp_month : "0"
                            + temp_month) + "-"
                            + (i > 9 ? "" + i : "0" + i);
                    map = new HashMap<String, String>();
                    map.put("day", i + "");
                    map.put("time", tempStr);
                    map.put("isToday", "0"); // 1是今天
                    map.put("isMonth", "0"); // 1是本月
                    try {
                        if (CalHoliday(Integer.valueOf("" + temp_month
                                + (i > 9 ? "" + i : "0" + i)))) {
                            map.put("lunar", holiday);
                        } else {
                            map.put("lunar",
                                    CalendarChange.CalendarChange(tempStr));
                        }
                        if (isRed) {
                            map.put("isHoliday", "1"); // 1节日
                            isRed = false;
                        } else {
                            map.put("isHoliday", "0"); // 1节日
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    data.add(0, map);
                }
            }
        } else {
            for (int i = 31; i > 31 - te_week; i--) {
                String tempStr = temp_year + "-"
                        + (temp_month > 9 ? "" + temp_month : "0" + temp_month)
                        + "-" + (i > 9 ? "" + i : "0" + i);
                map = new HashMap<String, String>();
                map.put("day", i + "");
                map.put("time", tempStr);
                map.put("isToday", "0"); // 1是今天
                map.put("isMonth", "0"); // 1是本月
                try {
                    if (CalHoliday(Integer.valueOf("" + temp_month
                            + (i > 9 ? "" + i : "0" + i)))) {
                        map.put("lunar", holiday);
                    } else {
                        map.put("lunar", CalendarChange.CalendarChange(tempStr));
                    }
                    if (isRed) {
                        map.put("isHoliday", "1"); // 1节日
                        isRed = false;
                    } else {
                        map.put("isHoliday", "0"); // 1节日
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                data.add(0, map);
            }
        }
        if (temp_month == 12) {
            temp_year++;
            temp_month = 1;
        } else {
            temp_month = temp_month + 1;
        }
        calLeapYear(temp_year);
        if (temp_month == 4 || temp_month == 6 || temp_month == 9
                || temp_month == 11) {
            for (int i = to_day + 1; i <= 30; i++) {
                String tempStr = temp_year + "-"
                        + (temp_month > 9 ? "" + temp_month : "0" + temp_month)
                        + "-" + (i > 9 ? "" + i : "0" + i);
                map = new HashMap<String, String>();
                map.put("day", i + "");
                map.put("time", tempStr);
                map.put("isToday", "0"); // 1是今天
                map.put("isMonth", "1"); // 1是本月
                try {
                    if (CalHoliday(Integer.valueOf("" + temp_month
                            + (i > 9 ? "" + i : "0" + i)))) {
                        map.put("lunar", holiday);
                    } else {
                        map.put("lunar", CalendarChange.CalendarChange(tempStr));
                    }
                    if (isRed) {
                        map.put("isHoliday", "1"); // 1节日
                        isRed = false;
                    } else {
                        map.put("isHoliday", "0"); // 1节日
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                data.add(map);
            }
        } else if (temp_month == 2) {
            if (isLeap) {
                for (int i = to_day + 1; i <= 29; i++) {
                    String tempStr = temp_year
                            + "-"
                            + (temp_month > 9 ? "" + temp_month : "0"
                            + temp_month) + "-"
                            + (i > 9 ? "" + i : "0" + i);
                    map = new HashMap<String, String>();
                    map.put("day", i + "");
                    map.put("time", tempStr);
                    map.put("isToday", "0"); // 是今天
                    map.put("isMonth", "1"); // 1是本月
                    try {
                        if (CalHoliday(Integer.valueOf("" + temp_month
                                + (i > 9 ? "" + i : "0" + i)))) {
                            map.put("lunar", holiday);
                        } else {
                            map.put("lunar",
                                    CalendarChange.CalendarChange(tempStr));
                        }
                        if (isRed) {
                            map.put("isHoliday", "1"); // 1节日
                            isRed = false;
                        } else {
                            map.put("isHoliday", "0"); // 1节日
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    data.add(map);
                }
            } else {
                for (int i = to_day + 1; i <= 28; i++) {
                    String tempStr = temp_year
                            + "-"
                            + (temp_month > 9 ? "" + temp_month : "0"
                            + temp_month) + "-"
                            + (i > 9 ? "" + i : "0" + to_day);
                    map = new HashMap<String, String>();
                    map.put("day", i + "");
                    map.put("time", tempStr);
                    map.put("isToday", "0"); // 是今天
                    map.put("isMonth", "1"); // 1是本月
                    try {
                        if (CalHoliday(Integer.valueOf("" + temp_month
                                + (i > 9 ? "" + i : "0" + i)))) {
                            map.put("lunar", holiday);
                        } else {
                            map.put("lunar",
                                    CalendarChange.CalendarChange(tempStr));
                        }
                        if (isRed) {
                            map.put("isHoliday", "1"); // 1节日
                            isRed = false;
                        } else {
                            map.put("isHoliday", "0"); // 1节日
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    data.add(map);
                }
            }
        } else {
            for (int i = to_day + 1; i <= 31; i++) {
                String tempStr = temp_year + "-"
                        + (temp_month > 9 ? "" + temp_month : "0" + temp_month)
                        + "-" + (i > 9 ? "" + i : "0" + i);
                map = new HashMap<String, String>();
                map.put("day", i + "");
                map.put("time", tempStr);
                map.put("isToday", "0"); // 是今天
                map.put("isMonth", "1"); // 1是本月
                try {
                    if (CalHoliday(Integer.valueOf("" + temp_month
                            + (i > 9 ? "" + i : "0" + i)))) {
                        map.put("lunar", holiday);
                    } else {
                        map.put("lunar", CalendarChange.CalendarChange(tempStr));
                    }
                    if (isRed) {
                        map.put("isHoliday", "1"); // 1节日
                        isRed = false;
                    } else {
                        map.put("isHoliday", "0"); // 1节日
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                data.add(map);
            }
        }
        if (temp_month >= 12) {
            temp_year++;
            temp_month = 1;
        } else {
            temp_month++;
        }
        int mm = data.size();
        for (int i = 1; i <= 42 - mm; i++) {
            String tempStr = temp_year + "-"
                    + (temp_month > 9 ? "" + temp_month : "0" + temp_month)
                    + "-" + (i > 9 ? "" + i : "0" + i);
            map = new HashMap<String, String>();
            map.put("day", i + "");
            map.put("time", tempStr);
            map.put("isToday", "0"); // 是今天
            map.put("isMonth", "0"); // 1是本月
            try {
                if (CalHoliday(Integer.valueOf("" + temp_month
                        + (i > 9 ? "" + i : "0" + i)))) {
                    map.put("lunar", holiday);
                } else {
                    map.put("lunar", CalendarChange.CalendarChange(tempStr));
                }
                if (isRed) {
                    map.put("isHoliday", "1"); // 1节日
                    isRed = false;
                } else {
                    map.put("isHoliday", "0"); // 1节日
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            data.add(map);
        }
        return data;
    }

    public boolean CalHoliday(int t) {
        boolean is = false;
        switch (t / 100) {
            case 2:
                if (t == solartime[0]) {
                    holiday = "立春";
                    is = true;
                } else if (t == solartime[1]) {
                    holiday = "雨水";
                    is = true;
                }
                break;
            case 3:
                if (t == solartime[2]) {
                    holiday = "惊蛰";
                    is = true;
                } else if (t == solartime[3]) {
                    holiday = "春分";
                    is = true;
                }
                break;
            case 4:
                if (t == solartime[4]) {
                    holiday = "清明";
                    is = true;
                } else if (t == solartime[5]) {
                    holiday = "谷雨";
                    is = true;
                }
                break;
            case 5:
                if (t == solartime[6]) {
                    holiday = "立夏";
                    is = true;
                } else if (t == solartime[7]) {
                    holiday = "小满";
                    is = true;
                }
                break;
            case 6:
                if (t == solartime[8]) {
                    holiday = "芒种";
                    is = true;
                } else if (t == solartime[9]) {
                    holiday = "夏至";
                    is = true;
                }
                break;
            case 7:
                if (t == solartime[10]) {
                    holiday = "小暑";
                    is = true;
                } else if (t == solartime[11]) {
                    holiday = "大暑";
                    is = true;
                }
                break;
            case 8:
                if (t == solartime[12]) {
                    holiday = "立秋";
                    is = true;
                } else if (t == solartime[13]) {
                    holiday = "处暑";
                    is = true;
                }
                break;
            case 9:
                if (t == solartime[14]) {
                    holiday = "白露";
                    is = true;
                } else if (t == solartime[15]) {
                    holiday = "秋分";
                    is = true;
                }
                break;
            case 10:
                if (t == solartime[16]) {
                    holiday = "寒露";
                    is = true;
                } else if (t == solartime[17]) {
                    holiday = "霜降";
                    is = true;
                }
                break;
            case 11:
                if (t == solartime[18]) {
                    holiday = "立冬";
                    is = true;
                } else if (t == solartime[19]) {
                    holiday = "小雪";
                    is = true;
                }
                break;
            case 12:
                if (t == solartime[20]) {
                    holiday = "大雪";
                    is = true;
                } else if (t == solartime[21]) {
                    holiday = "冬至";
                    is = true;
                }
                break;
            case 1:
                if (t == solartime[22]) {
                    holiday = "小寒";
                    is = true;
                } else if (t == solartime[23]) {
                    holiday = "大寒";
                    is = true;
                }
                break;
        }
        switch (t) {
            case 101:
                holiday = "元旦";
                isRed = true;
                is = true;
                break;
            case 214:
                holiday = "情人节";
                is = true;
                break;
            case 308:
                holiday = "妇女节";
                is = true;
                break;
            case 312:
                holiday = "植树节";
                is = true;
                break;
            case 315:
                holiday = "消费日";
                is = true;
                break;
            case 401:
                holiday = "愚人节";
                is = true;
                break;
            // case 407:
            // holiday="卫生日";
            // is=true;
            // break;
            case 501:
                holiday = "劳动节";
                is = true;
                break;
            case 504:
                holiday = "青年节";
                is = true;
                break;
            // case 512:
            // holiday="护士节";
            // is=true;
            // break;
            // case 513:
            // holiday="助残日";
            // is=true;
            // break;

            case 601:
                holiday = "儿童节";
                is = true;
                break;
            case 605:
                holiday = "世界环境日";
                is = true;
                break;
            case 701:
                holiday = "建党节";
                is = true;
                break;
            case 801:
                holiday = "建军节";
                is = true;
                break;
            case 910:
                holiday = "教师节";
                is = true;
                break;
            case 1001:
                holiday = "国庆节";
                is = true;
                break;
            case 1225:
                holiday = "圣诞节";
                is = true;
                break;
            default:
                // is=false;
                break;
        }

        return is;
    }

    String Today = "";

    @SuppressWarnings("deprecation")
    public void GenView() {
        dataLinear.removeAllViews();
        mLayoutParamss.weight = 1;
        LayoutInflater lif = LayoutInflater.from(CommonSearchTagActivity.this);
        LinearLayout temp = new LinearLayout(CommonSearchTagActivity.this);
        int size = data.size();
        for (int i = 0; i < size; i++) {
            View convertView = lif.inflate(R.layout.gritem, null);
            TextView time = (TextView) convertView.findViewById(R.id.time);
            TextView lunar = (TextView) convertView.findViewById(R.id.lunar);
            TextView fraction = (TextView) convertView.findViewById(R.id.fraction);
            LinearLayout itemroot = (LinearLayout) convertView.findViewById(R.id.itemroot);
            HashMap<String, String> map = data.get(i);
            if ((i + 1) < size) {
                HashMap<String, String> map2 = data.get(i + 1);
                if (map2.get("lunar").equals("春节")) {
                    map.put("lunar", "除夕");
                }
            }
            String day = map.get("day");
            if (map.get("isMonth").equals("1"))// 1是本月
            {
                itemroot.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_riliactivity));
                if (map.get("isToday").equals("1"))// 1是今天
                {
                    time.setTextColor(getResources().getColor(R.color.sunday_txt));
                    lunar.setTextColor(getResources().getColor(R.color.sunday_txt));
//                    itemroot.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_riliactivity_jintian));
                } else {
                    itemroot.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_riliactivity));
                }
                if (Today.isEmpty()) {
                    if (map.get("isToday").equals("1"))// 1是今天
                    {
                        time.setTextColor(getResources().getColor(R.color.sunday_txt));
                        lunar.setTextColor(getResources().getColor(R.color.sunday_txt));
                        itemroot.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_riliactivity_jintian));
                    } else {
                        itemroot.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_riliactivity));
                    }
                } else {
                    if (Today.substring(8, Today.length()).equals("" + (Integer.parseInt(day) > 9 ? day : "0" + day))) {
//                        time.setTextColor(getResources().getColor(R.color.sunday_txt));
//                        lunar.setTextColor(getResources().getColor(R.color.sunday_txt));
                        itemroot.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_riliactivity_jintian));
                    } else {
                        itemroot.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_riliactivity));
                    }
                }
//                int m = (i + 1) % 7;
//                if (m == 1 || m == 0) {
//                    time.setTextColor(Color.rgb(50, 79, 133));
//                }
                if (map.get("isHoliday").equals("1")) // 节日
                {
                    time.setTextColor(Color.RED);
                }
                itemroot.setTag(R.id.calendar_index, "1");//0其他,1是本月
            } else {
                time.setTextColor(getResources().getColor(R.color.othermonth_txt));
                lunar.setTextColor(getResources().getColor(R.color.othermonth_txt));
                itemroot.setBackgroundDrawable(getResources().getDrawable(R.drawable.bg_riliactivity));
                itemroot.setTag(R.id.calendar_index, "0");
            }
            String datestr = standard_year + "-" +
                    (standard_month > 9 ? standard_month : "0" + standard_month) + "-" +
                    (day.length() > 1 ? day : "0" + day);
            if (map.get("isMonth").equals("1")) {// 1是本月
                if (App.getDBcApplication().queryISNOTHOLIDAY(datestr).equals("1")) {//休息
                    fraction.setText("休");
                    fraction.setTextColor(getResources().getColor(R.color.sunday_txt));
                } else if (App.getDBcApplication().queryISNOTHOLIDAY(datestr).equals("2")) {//上班
                    fraction.setText("班");
                    fraction.setTextColor(getResources().getColor(R.color.title0));
                } else {
                    fraction.setText("");
                }
            }
            if (!map.get("isMonth").equals("1")) {
                time.setVisibility(View.GONE);
                fraction.setVisibility(View.GONE);
                lunar.setVisibility(View.GONE);
            }

            time.setText(day);
            lunar.setText(map.get("lunar"));
            itemroot.setTag(day);
            itemroot.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String day = v.getTag().toString();
                    // 0其他,1是本月
                    String calendar_index = v.getTag(R.id.calendar_index).toString();
                    if ("1".equals(calendar_index)) {
                        Intent intent = null;
                        String dateTime = Integer.toString(standard_year)
                                + "-"
                                + (standard_month > 9 ? "" + standard_month
                                : "0" + standard_month) + "-"
                                + (Integer.parseInt(day) > 9 ? day : "0" + day);
                        Message message = new Message();
                        message.what = 9;
                        message.obj = "\"" + dateTime + "\"\n设置日期";
                        Today = dateTime;
                        handlerrili.sendMessage(message);
                    }
                }
            });
            if ((i + 1) % 7 != 0) {
                temp.addView(convertView, mLayoutParamss);
            } else {
                if (i != 0) {
                    temp.addView(convertView, mLayoutParamss);
                    dataLinear.addView(temp, mLayoutParamss);
                    temp = new LinearLayout(CommonSearchTagActivity.this);
                }
            }
        }
    }

    /*
     * 基姆拉尔森计算公式 QgW4jIbx W= (d+2*m+3*(m+1)/5+y+y/4-y/100+y/400) mod 7 /
     *
     * d 天 m 月 y 年 1月2月换算为去年的13 14月计算
     *
     * 基姆拉尔森计算公式的C#的实现 %NfbgJcL_ //y：年，m：月，d：日。在参数都只传入相应的整数
     */
    private int calWeek(int y, int m, int d) {
        int a = 7; // 用来保存计算得到的星期几的整数 Dz>v;%$S-
        if ((m == 1) || (m == 2))// 如果是一月或二月进行换算 uWKc .
        {
            m += 12;
            y--;
        }
        a = (d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) % 7; // 得到的星期几的整数
        // 
        // 7ehs+GI
        a++;
        if (a == 7) {
            a = 0;
        }
        return a;
    }

    public void calLeapYear(int i) {
        if (i % 100 == 0) {
            if (i % 400 == 0) {
                isLeap = true;
            } else {
                isLeap = false;
            }
        } else {
            if (i % 4 == 0) {
                isLeap = true;
            } else {
                isLeap = false;
            }
        }
    }

    private void initBeforeDiaLog(TextView tixing_tv, Map<String, String> mMap, String beforeType) {
        Dialog dialog = new Dialog(CommonSearchTagActivity.this, R.style.dialog_translucent);
        Window window = dialog.getWindow();
        WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
        window.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
        window.setAttributes(params);// 设置生效

        LayoutInflater fac = LayoutInflater.from(CommonSearchTagActivity.this);
        View more_pop_menu = fac.inflate(R.layout.dialog_naozhongtiqian2, null);
        dialog.setCanceledOnTouchOutside(true);
        dialog.setContentView(more_pop_menu);
        params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        params.width = CommonSearchTagActivity.this.getWindowManager().getDefaultDisplay().getWidth();
        dialog.show();
        new MyBeforeOnClick(dialog, more_pop_menu, tixing_tv, mMap, beforeType);
    }

    Map<Integer, Boolean> map = new HashMap<Integer, Boolean>();
    private LinearLayout ll;
    private TextView tixingcishu_tv;

    int indexti = 0;
    GridBeforeAdapter adapterti = null;

    class MyBeforeOnClick implements View.OnClickListener {

        private View view;
        private Dialog dialog;
        private GridView before_gridview;
        private LinearLayout detail_close;
        private TextView tixing_tv;

        private String[] befStrings;
        private String beforeType;

        int height;

        boolean beforeFag;
        Map<String, String> mMap;

        public MyBeforeOnClick(Dialog dialog, View view, TextView tixing_tv, Map<String, String> mMap, String beforeType) {
            this.dialog = dialog;
            this.view = view;
            this.mMap = mMap;
            this.tixing_tv = tixing_tv;
            this.beforeType = beforeType;
            initview();
            initdata();
        }

        private void initview() {
            detail_close = (LinearLayout) view.findViewById(R.id.detail_close);
            ll = (LinearLayout) view.findViewById(R.id.ll);
            tixingcishu_tv = (TextView) view.findViewById(R.id.tixingcishu_tv);
            before_gridview = (GridView) view.findViewById(R.id.before_gridview);
            height = Utils.dipTopx(CommonSearchTagActivity.this, 80);
            befStrings = CommonSearchTagActivity.this.getResources().getStringArray(R.array.before_time);
            tixingcishu_tv.setText("一次提醒");

            detail_close.setOnClickListener(this);
        }

        private void initdata() {
            if (!"".equals(mMap.get(ScheduleTable.schID)) && mMap.get(ScheduleTable.schID) != null) {
                if (1 == isAlarm || 3 == isAlarm) {
                    map.put(0, true);
                } else {
                    map.put(0, false);
                }
                if (isAlarm == 3) {
                    tixingcishu_tv.setText("两次提醒");
                } else {
                    tixingcishu_tv.setText("一次提醒");
                }
                String beforeStr = "";
                if (beforeType.equals("准时提醒")) {
                    indexti = 0;
                } else if (beforeType.equals("提前5分钟")) {
                    beforeStr = "5分钟";
                    indexti = 1;
                } else if (beforeType.equals("提前15分钟")) {
                    beforeStr = "15分钟";
                    indexti = 2;
                } else if (beforeType.equals("提前30分钟")) {
                    beforeStr = "30分钟";
                    indexti = 3;
                } else if (beforeType.equals("提前1小时")) {
                    beforeStr = "1小时";
                    indexti = 4;
                } else if (beforeType.equals("提前2小时")) {
                    beforeStr = "2小时";
                    indexti = 5;
                } else if (beforeType.equals("提前1天")) {
                    beforeStr = "1天";
                    indexti = 6;
                } else if (beforeType.equals("提前2天")) {
                    beforeStr = "2天";
                    indexti = 7;
                } else if (beforeType.equals("提前1周")) {
                    beforeStr = "1周";
                    indexti = 8;
                } else if (beforeType.equals("准时提醒\n提前5分钟")) {
                    beforeStr = "5分钟";
                    indexti = 1;
                } else if (beforeType.equals("准时提醒\n提前15分钟")) {
                    beforeStr = "15分钟";
                    indexti = 2;
                } else if (beforeType.equals("准时提醒\n提前30分钟")) {
                    beforeStr = "30分钟";
                    indexti = 3;
                } else if (beforeType.equals("准时提醒\n提前1小时")) {
                    beforeStr = "1小时";
                    indexti = 4;
                } else if (beforeType.equals("准时提醒\n提前2小时")) {
                    beforeStr = "2小时";
                    indexti = 5;
                } else if (beforeType.equals("准时提醒\n提前1天")) {
                    beforeStr = "1天";
                    indexti = 6;
                } else if (beforeType.equals("准时提醒\n提前2天")) {
                    beforeStr = "2天";
                    indexti = 7;
                } else if (beforeType.equals("准时提醒\n提前1周")) {
                    beforeStr = "1周";
                    indexti = 8;
                }
                map.put(indexti, true);
                adapterti = new GridBeforeAdapter(CommonSearchTagActivity.this, befStrings, height,
                        indexti, tixing_tv, mMap);
                before_gridview.setAdapter(adapterti);

            } else {
                map.put(0, true);
                String beforeStr = "";
                if (beforeType.equals("准时提醒")) {
                    indexti = 0;
                } else if (beforeType.equals("提前5分钟")) {
                    beforeStr = "5分钟";
                    indexti = 1;
                } else if (beforeType.equals("提前15分钟")) {
                    beforeStr = "15分钟";
                    indexti = 2;
                } else if (beforeType.equals("提前30分钟")) {
                    beforeStr = "30分钟";
                    indexti = 3;
                } else if (beforeType.equals("提前1小时")) {
                    beforeStr = "1小时";
                    indexti = 4;
                } else if (beforeType.equals("提前2小时")) {
                    beforeStr = "2小时";
                    indexti = 5;
                } else if (beforeType.equals("提前1天")) {
                    beforeStr = "1天";
                    indexti = 6;
                } else if (beforeType.equals("提前2天")) {
                    beforeStr = "2天";
                    indexti = 7;
                } else if (beforeType.equals("提前1周")) {
                    beforeStr = "1周";
                    indexti = 8;
                } else if (beforeType.equals("准时提醒\n提前5分钟")) {
                    beforeStr = "5分钟";
                    indexti = 1;
                } else if (beforeType.equals("准时提醒\n提前15分钟")) {
                    beforeStr = "15分钟";
                    indexti = 2;
                } else if (beforeType.equals("准时提醒\n提前30分钟")) {
                    beforeStr = "30分钟";
                    indexti = 3;
                } else if (beforeType.equals("准时提醒\n提前1小时")) {
                    beforeStr = "1小时";
                    indexti = 4;
                } else if (beforeType.equals("准时提醒\n提前2小时")) {
                    beforeStr = "2小时";
                    indexti = 5;
                } else if (beforeType.equals("准时提醒\n提前1天")) {
                    beforeStr = "1天";
                    indexti = 6;
                } else if (beforeType.equals("准时提醒\n提前2天")) {
                    beforeStr = "2天";
                    indexti = 7;
                } else if (beforeType.equals("准时提醒\n提前1周")) {
                    beforeStr = "1周";
                    indexti = 8;
                }
                map.put(indexti, true);
                adapterti = new GridBeforeAdapter(CommonSearchTagActivity.this, befStrings, height, indexti, tixing_tv, mMap);
                before_gridview.setAdapter(adapterti);
            }
        }

        @Override
        public void onClick(View v) {
            Animation translateIn0 = new TranslateAnimation(-view.getWidth(),
                    0, 0, 0);
            Animation translateIn1 = new TranslateAnimation(view.getWidth(), 0,
                    0, 0);
            translateIn0.setDuration(400);
            translateIn1.setDuration(400);
            switch (v.getId()) {
                case R.id.detail_close:
                    dialog.dismiss();
                    break;
                default:
                    break;
            }
        }
    }

    private void initMap() {
        for (int i = 1; i < 9; i++) {
            if (i == indexti) {
                map.put(i, true);
            } else {
                map.put(i, false);
            }
        }
    }

    private void initMap1() {
        for (int i = 1; i < 9; i++) {
            map.put(i, false);
        }
    }

    int isAlarm = 0;

    public class GridBeforeAdapter extends BaseAdapter {

        private Context context;
        private String[] beforeTime;
        private int height;
        private int lastIndex;
        String str = "一次提醒";
        TextView tixing;
        Map<String, String> mMap;

        public GridBeforeAdapter(Context context, String[] beforeTime,
                                 int height, int lastIndex, TextView tixing, Map<String, String> mMap) {
            this.context = context;
            this.beforeTime = beforeTime;
            this.height = height;
            this.lastIndex = lastIndex;
            this.tixing = tixing;
            this.mMap = mMap;
            initMap();
        }

        @Override
        public int getCount() {
            return beforeTime.length;
        }

        @Override
        public Object getItem(int position) {
            return beforeTime[position];
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        public String[] getBeforeTime() {
            return beforeTime;
        }

        @Override
        public View getView(final int position, View convertView,
                            ViewGroup parent) {
            View view = convertView;
            GridBeforeAdapter.ViewWapper viewWapper = null;
            if (view == null) {
                view = LayoutInflater.from(CommonSearchTagActivity.this).inflate(
                        R.layout.adapter_grid_before_item, null);
                viewWapper = new GridBeforeAdapter.ViewWapper(view);
                view.setTag(viewWapper);
            } else {
                viewWapper = (GridBeforeAdapter.ViewWapper) view.getTag();
            }
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.MATCH_PARENT, height);
            LinearLayout before_ll = viewWapper.getBeforLL();
            before_ll.setLayoutParams(params);

            TextView before_tv = viewWapper.getBeforTime();
            TextView before_tv_state = viewWapper.getBeforState();
            String beforTime = beforeTime[position];
            if (str.equals("一次提醒")) {
                str = "准时提醒";
            }
            if (beforTime.equals(str)) {
                before_tv.setText(beforTime);
                before_tv.setTextSize(15);
            } else {
                before_tv.setText(beforTime.split("-")[0]);
                before_tv_state.setText(beforTime.split("-")[1]);
            }


            before_ll.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    if (position == 0) {
                        if (map.get(0)) {
                            map.put(position, false);
                        } else {
                            map.put(position, true);
                        }
                    } else {
                        if (position == lastIndex) {
                            if (map.get(position)) {
                                map.put(position, false);
                            } else {
                                map.put(position, true);
                            }
                        } else {
                            initMap1();
                            map.put(position, true);
                        }

                        lastIndex = position;
                    }

                    adapterti.notifyDataSetChanged();

                    int before = 0;
                    if (map.get(0)) {
                        before = 0;
                    }
                    if (map.get(1)) {
                        before = 5;
                    } else if (map.get(2)) {
                        before = 15;
                    } else if (map.get(3)) {
                        before = 30;
                    } else if (map.get(4)) {
                        before = 60;
                    } else if (map.get(5)) {
                        before = 120;
                    } else if (map.get(6)) {
                        before = 24 * 60;
                    } else if (map.get(7)) {
                        before = 48 * 60;
                    } else if (map.get(8)) {
                        before = 7 * 24 * 60;
                    }

                    int select = 0;
                    for (int i = 0; i < beforeTime.length; i++) {
                        if (map.get(i)) {
                            select++;
                        }
                    }
                    if (select == 1) {
                        tixingcishu_tv.setText("一次提醒");
                    } else if (select == 2) {
                        tixingcishu_tv.setText("两次提醒");
                    }
                    if (position == 0) {
                        if (map.get(0)) {
                            if (select == 1) {
                                mMap.put(ScheduleTable.schIsAlarm, "1");
                                mMap.put(ScheduleTable.schBeforeTime, "0");
                                App.getDBcApplication().updateSceduleDataTiQianTime(Integer.valueOf(mMap.get(ScheduleTable.schID)), 0, 1);
                            } else if (select == 2) {
                                mMap.put(ScheduleTable.schIsAlarm, "3");
                                mMap.put(ScheduleTable.schBeforeTime, before + "");
                                App.getDBcApplication().updateSceduleDataTiQianTime(Integer.valueOf(mMap.get(ScheduleTable.schID)), before, 3);
                            }
                        } else {
                            if (select == 1) {
                                mMap.put(ScheduleTable.schIsAlarm, "2");
                                mMap.put(ScheduleTable.schBeforeTime, before + "");
                                App.getDBcApplication().updateSceduleDataTiQianTime(Integer.valueOf(mMap.get(ScheduleTable.schID)), before, 2);
                            }
                        }
                    } else {
                        if (map.get(position)) {
                            if (select == 1) {
                                mMap.put(ScheduleTable.schIsAlarm, "2");
                                mMap.put(ScheduleTable.schBeforeTime, before + "");
                                App.getDBcApplication().updateSceduleDataTiQianTime(Integer.valueOf(mMap.get(ScheduleTable.schID)), before, 2);
                            } else if (select == 2) {
                                mMap.put(ScheduleTable.schIsAlarm, "3");
                                mMap.put(ScheduleTable.schBeforeTime, before + "");
                                App.getDBcApplication().updateSceduleDataTiQianTime(Integer.valueOf(mMap.get(ScheduleTable.schID)), before, 3);
                            }
                        } else {
                            if (select == 1) {
                                mMap.put(ScheduleTable.schIsAlarm, "1");
                                mMap.put(ScheduleTable.schBeforeTime, "0");
                                App.getDBcApplication().updateSceduleDataTiQianTime(Integer.valueOf(mMap.get(ScheduleTable.schID)), 0, 1);
                            }
                        }
                    }

                    loaddata(search_type);
                    QueryAlarmData.writeAlarm(CommonSearchTagActivity.this);

                }
            });

            int select = 0;
            for (int i = 0; i < beforeTime.length; i++) {
                if (map.get(i)) {
                    select++;
                }
            }
            if (position == 0) {
                if (map.get(position)) {
                    before_ll.setBackgroundColor(getResources().getColor(
                            R.color.sunday_txt));
                    before_tv.setTextColor(getResources().getColor(
                            R.color.white));

                } else {
                    before_ll.setBackgroundColor(getResources().getColor(
                            R.color.choosedate));
                    before_tv.setTextColor(getResources().getColor(
                            R.color.gongkai_txt));
                }
            } else {
                if (map.get(position)) {
                    before_ll.setBackgroundColor(getResources().getColor(R.color.mingtian_color));
                    before_tv.setTextColor(getResources().getColor(R.color.white));
                    before_tv_state.setTextColor(getResources().getColor(R.color.white));
                } else {
                    before_ll.setBackgroundColor(getResources().getColor(R.color.choosedate));
                    before_tv.setTextColor(getResources().getColor(R.color.gongkai_txt));
                    before_tv_state.setTextColor(getResources().getColor(R.color.gongkai_txt));
                }
            }


            String selecttime;
            if ("全天".equals(mMap.get(ScheduleTable.schTime))) {
                selecttime = sharedPrefUtil.getString(CommonSearchTagActivity.this, ShareFile.USERFILE,
                        ShareFile.ALLTIME, "08:58");
            } else {
                selecttime = mMap.get(ScheduleTable.schTime);
            }
            if (select == 1) {
                ll.setVisibility(View.VISIBLE);
                if (map.get(0)) {
                    tixing.setText("\"一次提醒\"");
                    isAlarm = 1;
//                    String retStrFormatNowDate = DateUtil.formatDate(DateUtil.parseDate(mMap.get(ScheduleTable.schDate)));
                } else {
                    tixing.setText("\"一次提醒\"");
//                    if (map.get(position)) {
                    isAlarm = 2;
//                        if ("5-分钟".equals(beforTime)) {
//                            tixing.setText("提前5分钟");
//                        } else if ("15-分钟".equals(beforTime)) {
//                            tixing.setText("提前15分钟");
//                        } else if ("30-分钟".equals(beforTime)) {
//                            tixing.setText("提前30分钟");
//                        } else if ("1-小时".equals(beforTime)) {
//                            tixing.setText("提前1小时");
//                        } else if ("2-小时".equals(beforTime)) {
//                            tixing.setText("提前2小时");
//                        } else if ("1-天".equals(beforTime)) {
//                            tixing.setText("提前1天");
//                        } else if ("2-天".equals(beforTime)) {
//                            tixing.setText("提前2天");
//                        } else if ("1-周".equals(beforTime)) {
//                            tixing.setText("提前1周");
//                        }
//                        // Date nowTime = new
//                        // Date(System.currentTimeMillis()
//                        // - before * 60 * 1000);
//                        String retStrFormatNowDate = DateUtil
//                                .formatDateTime(DateUtil
//                                        .parseDateTime(mMap.get(ScheduleTable.schDate) + " " + selecttime));
//                    }
                }
            } else if (select == 2) {
                ll.setVisibility(View.VISIBLE);
                isAlarm = 3;
                tixing.setText("\"两次提醒\"");
//                if (map.get(position)) {
//                    if ("5-分钟".equals(beforTime)) {
//                        tixing.setText(str + "\n提前5分钟");
//                    } else if ("15-分钟".equals(beforTime)) {
//                        tixing.setText(str + "\n提前15分钟");
//                    } else if ("30-分钟".equals(beforTime)) {
//                        tixing.setText(str + "\n提前30分钟");
//                    } else if ("1-小时".equals(beforTime)) {
//                        tixing.setText(str + "\n提前1小时");
//                    } else if ("2-小时".equals(beforTime)) {
//                        tixing.setText(str + "\n提前2小时");
//                    } else if ("1-天".equals(beforTime)) {
//                        tixing.setText(str + "\n提前1天");
//                    } else if ("2-天".equals(beforTime)) {
//                        tixing.setText(str + "\n提前2天");
//                    } else if ("1-周".equals(beforTime)) {
//                        tixing.setText(str + "\n提前1周");
//                    }
//                    int number = 0;
//                    if (str.equals(beforTime)) {
//                        number = 0;
//                    } else if ("5-分钟".equals(beforTime)) {
//                        number = 5;
//                    } else if ("15-分钟".equals(beforTime)) {
//                        number = 15;
//                    } else if ("30-分钟".equals(beforTime)) {
//                        number = 30;
//                    } else if ("1-小时".equals(beforTime)) {
//                        number = 60;
//                    } else if ("2-小时".equals(beforTime)) {
//                        number = 120;
//                    } else if ("1-天".equals(beforTime)) {
//                        number = 24 * 60;
//                    } else if ("2-天".equals(beforTime)) {
//                        number = 48 * 60;
//                    } else if ("1-周".equals(beforTime)) {
//                        number = 7 * 24 * 60;
//                    }
//                    if (number != 0) {
//                        String beforenowtime = DateUtil.formatDateTime(DateUtil
//                                .parseDateTime(mMap.get(ScheduleTable.schDate) + " " + selecttime));
//                        Date nowtime = new Date(DateUtil.parseDateTime(
//                                beforenowtime).getTime()
//                                - number * 60 * 1000);
//                        String retStrFormatNowDate = DateUtil.formatDateTime(nowtime);
//                    }
//                }
            } else {
                map.put(0, true);
                ll.setVisibility(View.VISIBLE);
                tixing.setText("\"一次提醒\"");
            }
            return view;
        }

        class ViewWapper {

            private View view;
            private LinearLayout before_ll;
            private TextView before_tv;
            private TextView before_state;

            private ViewWapper(View view) {
                this.view = view;
            }

            private LinearLayout getBeforLL() {
                if (before_ll == null) {
                    before_ll = (LinearLayout) view
                            .findViewById(R.id.before_ll);
                }
                return before_ll;
            }

            private TextView getBeforTime() {
                if (before_tv == null) {
                    before_tv = (TextView) view.findViewById(R.id.before_tv);
                }
                return before_tv;
            }

            private TextView getBeforState() {
                if (before_state == null) {
                    before_state = (TextView) view
                            .findViewById(R.id.before_state);
                }
                return before_state;
            }
        }
    }

    class ViewAdapter extends PagerAdapter {
        private List<View> viewList;//数据源

        public ViewAdapter(List<View> viewList) {
            this.viewList = viewList;
        }

        @Override
        public int getCount() {
            return viewList.size();
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            container.addView(viewList.get(position));
            return viewList.get(position);
        }
    }

}
